简体   繁体   English

解决方案在Visual Studio中构建,但Jenkins抛出资产异常

[英]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.

相关问题 MySQLConnection在Visual Studio中引发异常 - MySQLConnection throws an Exception in Visual Studio Visual Studio生成解决方案,但命令行中的MSBuild失败 - Visual Studio builds solution but MSBuild from the command line fails 将现有网站添加到Visual Studio解决方案会引发System.InvalidOperationException - Adding an existing website to Visual Studio solution throws a System.InvalidOperationException 为什么我的解决方案在Visual Studio中构建,而不是使用msbuild从命令行构建? - How come my solution builds in Visual Studio but not from the command line using msbuild? Program.cs 上的 Visual Studio 中断不在引发异常的行上 - Visual Studio break on Program.cs not on the line that throws the exception Visual Studio解决方案参考 - Visual Studio Solution References Visual Studio大型解决方案 - Visual Studio Large Solution 自定义 Visual Studio 解决方案 - Custom Visual Studio solution Visual Studio 2017 工作室显示错误“此应用程序处于中断模式”并引发未处理的异常 - Visual Studio 2017 studio showing error 'This application is in break mode' and throws unhandled exception Visual Studio构建,但msbuild不构建。 - Visual studio builds but msbuild does not.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM