简体   繁体   English

Visual Studio无法发布

[英]Visual Studio cannot publish

I tried this with a new project just to confirm that I have not made any errors, but Visual Studio 2019 won't publish any dot net core project. 我尝试了一个新项目来确认我没有犯任何错误,但Visual Studio 2019不会发布任何点网核心项目。 Below is the error I am getting... Any help would be much appreciated... 以下是我遇到的错误...非常感谢您的帮助...

Severity Code Description Project File Line Suppression State Error The "TransformAppSettings" task failed unexpectedly. 严重性代码说明项目文件行抑制状态错误“ TransformAppSettings”任务意外失败。 System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. System.IO.FileNotFoundException:无法加载文件或程序集“ Newtonsoft.Json,版本= 10.0.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed”或其依赖项之一。 The system cannot find the file specified. 该系统找不到指定的文件。 File name: 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' at Microsoft.NET.Sdk.Publish.Tasks.AppSettingsTransform.UpdateDestinationConnectionStringEntries(String destinationAppSettingsFilePath, ITaskItem[] destinationConnectionStrings) at Microsoft.NET.Sdk.Publish.Tasks.TransformAppSettings.TransformAppSettingsInternal() at Microsoft.NET.Sdk.Publish.Tasks.TransformAppSettings.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() 文件名:Microsoft.NET上的'Newtonsoft.Json,版本= 1.0.0.0.0,文化=中性,PublicKeyToken =30ad4fe6b2a6aeed'。Microsoft.NET上的文件名:String destinationAppSettingsFilePath,ITaskItem [] destinationConnectionStrings。 Microsoft的Microsoft.NET的Sdk.Publish.Tasks.TransformAppSettings.TransformAppSettingsInternal()(Microsoft的Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()处的Sdk.Publish.Tasks.TransformAppSettings.TransformAppSettingsInternal()。 Build.BackEnd.TaskBuilder.d__26.MoveNext()

WRN: Assembly binding logging is turned OFF. WRN:程序集绑定日志记录已关闭。 To enable assembly bind failure logging, set the registry value [HKLM\\Software\\Microsoft\\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. 要启用程序集绑定失败日志记录,请将注册表值[HKLM \\ Software \\ Microsoft \\ Fusion!EnableLog](DWORD)设置为1。注意:程序集绑定失败日志记录会降低性能。 To turn this feature off, remove the registry value [HKLM\\Software\\Microsoft\\Fusion!EnableLog]. 要关闭此功能,请删除注册表值[HKLM \\ Software \\ Microsoft \\ Fusion!EnableLog]。 ProjectNameX 0 项目名称X 0

Here is my project file 这是我的项目文件

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
      <TargetFramework>netcoreapp3.0</TargetFramework>
      <UserSecretsId>aspnet-ProjectNameX-A0D4A38F-C3FA-4FD3-8EBC-0F2201FBCD57</UserSecretsId>
      <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
      <DockerfileContext>..\..\..</DockerfileContext>
  </PropertyGroup>


  <ItemGroup>
      <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.0.0-preview6.19307.2" />
      <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0-preview6.19307.2" />
      <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0-preview6.19307.2" />
      <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0-preview6.19304.10" />
      <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0-preview6.19304.10" />
      <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.12" />
  </ItemGroup>

While digging into visual studio folders, I found this... 在深入Visual Studio文件夹时,我发现了这个...

Visual Studio文件夹中的Nuget文件夹,带有Newtonsoft.Json dll文件

Please check if Newtonsoft.Json is referenced in your solution. 请检查您的解决方案中是否引用了Newtonsoft.Json It seems solution is not able to find it. 似乎解决方案无法找到它。

Below link shows how to add it. 下面的链接显示了如何添加它。

https://docs.microsoft.com/en-us/nuget/quickstart/install-and-use-a-package-in-visual-studio https://docs.microsoft.com/en-us/nuget/quickstart/install-and-use-a-package-in-visual-studio

Can you try publishing using a different Visual Studio 2019 instance? 您可以尝试使用其他Visual Studio 2019实例发布吗? Not with the preview version of course. 当然没有预览版。

The error has nothing to do with your project. 该错误与您的项目无关。 The error message "clearly" says that Microsoft.NET.Sdk.Publish.Tasks.TransformAppSettings.TransformAppSettingsInternal() tried to access Newtonsoft.Json. 错误消息“很明显”表明Microsoft.NET.Sdk.Publish.Tasks.TransformAppSettings.TransformAppSettingsInternal()试图访问Newtonsoft.Json。 This is obviously not your code. 这显然不是您的代码。

I find this very strange, as Microsoft.NET.Sdk.Publish.Tasks.dll exists in the same directory as Newtonsoft.Json.dll (check c:\\program files\\dotnet\\sdk), and it should have been compiled against the same version that ships. 我觉得这很奇怪,因为Microsoft.NET.Sdk.Publish.Tasks.dllNewtonsoft.Json.dll位于同一目录(请检查c:\\ program files \\ dotnet \\ sdk),并且应该针对相同版本。 You can confirm using something like ILSpy to see what the assembly version of Newtonsoft.Json is and what assembly reference the publish tasks dll has. 您可以使用ILSpy之类的工具进行确认,以查看Newtonsoft.Json的程序集版本是什么以及发布任务dll具有的程序集引用。 You can also better understand the paths and dlls that .NET used to try to load the dll, and why any dll with a matching filename was not used, using Fusion Logs. 您还可以使用Fusion Logs更好地了解.NET用于尝试加载dll的路径和dll,以及为何未使用具有匹配文件名的任何dll。 But I'm not going to write a tutorial on using Fusion Logs here. 但是我不会在这里编写有关使用融合日志的教程。

In any case, understanding why it's happening won't help you solve it. 无论如何,了解其发生的原因并不能帮助您解决它。 All you can really do is make sure you're using the latest SDK, install the newest version if not, and if the problem still exists using the Visual Studio "report a problem" tool to let the .NET Core team know about this. 您真正能做的就是确保您使用的是最新的SDK,如果没有,请安装最新版本,如果问题仍然存在,请使用Visual Studio“报告问题”工具让.NET Core团队了解这一点。

I faced similar issue. 我遇到了类似的问题。

In package manager console execute: Update-Package –reinstall Newtonsoft.Json 在程序包管理器控制台中,执行: Update-Package –reinstall Newtonsoft.Json

Though you haven't added package reference in .csproj. 尽管您尚未在.csproj中添加程序包引用。 Open the project.assets.json file in your obj folder and search for Newtonsoft.Json you would find the real version you refer to. 打开obj文件夹中的project.assets.json文件,搜索Newtonsoft.Json您将找到所引用的真实版本。

So just check if binding redirect can help. 因此,只需检查绑定重定向是否可以提供帮助。 If not, check if this issue persists if you create a new .net core empty web-app. 如果不是,请检查是否在创建新的.net core空Web应用程序时仍然存在此问题。 Then publish it to locate the issue according to the result whether it succeeds or not. 然后将其发布以根据结果是否成功找到问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM