[英]Solution builds in Visual Studio but Jenkins throws an assets exception
I have a solution that consists of both single-target and multi-target projects. 我有一个包含单目标和多目标项目的解决方案。 The solution can be built in Visual Studio 2017 and Developer Command Prompt for VS 2017 without problems.
可以在Visual Studio 2017和VS 2017开发人员命令提示符中构建该解决方案,而不会出现问题。
I build the solution by below code in Developer Command Prompt for VS 2017 我通过VS 2017开发人员命令提示符中的以下代码构建解决方案
msbuild MySolution.sln /t:Rebuild /p:Configuration=Release
I want to do this process in Jenkins. 我想在詹金斯做这个过程。 Then I added below command to Jenkins.
然后我在詹金斯下面添加了命令。
pushd "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools"
call VsDevCmd.bat
msbuild "C:\Workspace\My Solution\MySolution.sln" /t:Build /p:Configuration=Release
When I build the Jenkins project it throws an exception. 当我构建Jenkins项目时,它将引发异常。
C:\Program Files\dotnet\sdk\2.1.101\Sdks\Microsoft.NET.Sdk\build\
Microsoft.PackageDependencyResolution.targets(327,5): error : Assets file
'C:\Workspace\My Solution\Source\MyProject\obj\project.assets.json' not found.
Run a NuGet package restore to generate this file.
Thanks a lot 非常感谢
Visual Studio usually will do the nuget package restore for you (It can be turned off in settings). Visual Studio通常会为您还原nuget程序包(可以在设置中将其关闭)。
Building the solution from the command line is a different story. 从命令行构建解决方案是另一回事。 You are not using visual studio, but rather plain old MSBuild.
您不是在使用Visual Studio,而是在使用简单的旧版MSBuild。 MSBuild does not know about your nuget package.
MSBuild不了解您的nuget软件包。
So you have to manually restore your nuget packages first. 因此,您必须首先手动还原nuget软件包。
pushd "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools"
call VsDevCmd.bat
nuget restore "C:\Workspace\My Solution\MySolution.sln"
msbuild "C:\Workspace\My Solution\MySolution.sln" /t:Build /p:Configuration=Release
Jenkins cannot recognize msbuild command. Jenkins无法识别msbuild命令。 When I change the code like below it started working.
当我像下面那样更改代码时,它开始工作。
C:\nuget.exe restore "C:\Workspace\My Solution\MySolution.sln"
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe" "C:\Workspace\My Solution\MySolution.sln" /t:Build /p:Configuration=Release;VisualStudioVersion=15.0
I added nuget restore command and changed msbuild command with full path of msbuild.exe . 我添加了nuget restore命令,并使用msbuild.exe的完整路径更改了msbuild命令。 Finally I put VisualStudioVersion as a parameter.
最后,我将VisualStudioVersion作为参数。
Thanks @c-johnson 谢谢@ c-johnson
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.