visual studio 2017 publish asp.net core

2019-07-25 11:19发布

I have Visual Studio 2017 Enterprise 15.3.2 and rather old project made in dotnet core 1.1.

If I publish my project in console using 'dotnet publish ....' It works perfectly.

But when I use Visual Studio, I can restore, build, run my project absolutely without problems. Only an issue I have when I try to publish using 'Publish..' context menu in the project. I publish the project simply into the folder.

Once I make publishing I have suddenly a error and cannot assembly a project. Here is a error I have:

System.InvalidCastException: [A]NuGet.ProjectModel.LockFile cannot be cast to [B]NuGet.ProjectModel.LockFile. Type A originates from 'NuGet.ProjectModel, Version=4.3.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'LoadFrom' at location 'C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\tools\net46\NuGet.ProjectModel.dll'. Type B originates from 'NuGet.ProjectModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'LoadFrom' at location 'C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\tools\net46\NuGet.ProjectModel.dll'.


  at Microsoft.NET.Build.Tasks.LockFileCache.GetLockFile(String path)
   at Microsoft.NET.Build.Tasks.GenerateRuntimeConfigurationFiles.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

Help needed.

2条回答
Juvenile、少年°
2楼-- · 2019-07-25 11:53

Another way is:

Simply delete/rename global.json file from your Core 2.0 project :) .

查看更多
聊天终结者
3楼-- · 2019-07-25 11:56

I found a solution. In global.json change sdk version for:

"sdk": { "version": "2.0.0" },
查看更多
登录 后发表回答