visual studio 2017 publish asp.net core

旧街凉风 提交于 2020-01-05 03:41:06

问题


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.


回答1:


Another way is:

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




回答2:


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

"sdk": { "version": "2.0.0" },


来源:https://stackoverflow.com/questions/45920532/visual-studio-2017-publish-asp-net-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!