简体   繁体   中英

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. 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. 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. 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()

WRN: Assembly binding logging is turned OFF. 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. To turn this feature off, remove the registry value [HKLM\\Software\\Microsoft\\Fusion!EnableLog]. ProjectNameX 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文件夹中的Nuget文件夹,带有Newtonsoft.Json dll文件

Please check if Newtonsoft.Json is referenced in your solution. 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

Can you try publishing using a different Visual Studio 2019 instance? 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. 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. 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. 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. 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.

I faced similar issue.

In package manager console execute: Update-Package –reinstall Newtonsoft.Json

Though you haven't added package reference in .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.

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. Then publish it to locate the issue according to the result whether it succeeds or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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