C# 使用 MSBuild 在 Jenkins 中构建 .net 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10227967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
build .net application in Jenkins using MSBuild
提问by Bijoy K Jose
I have a .net application built on .net framework 3.5, I am trying to build this application on Jenkins CI server. I've added MSBuild plugin and and have added path to the .exe file of 2.0, 3.5 and 4.0 versions of MSBuild. But my building processes are failing by showing the below error message.
我有一个构建在 .net framework 3.5 上的 .net 应用程序,我正在尝试在 Jenkins CI 服务器上构建这个应用程序。我添加了 MSBuild 插件,并添加了 2.0、3.5 和 4.0 版 MSBuild 的 .exe 文件的路径。但是我的构建过程因显示以下错误消息而失败。
Path To MSBuild.exe: msbuild.exe
Executing command: cmd.exe /C msbuild.exe Neo.sln && exit %%ERRORLEVEL%%
[Test project] $ cmd.exe /C msbuild.exe Neo.sln && exit %%ERRORLEVEL%%
'msbuild.exe' is not recognized as an internal or external command,
operable program or batch file.
Build step 'Build a Visual Studio project or solution using MSBuild.' marked uild as failure
Finished: FAILURE
Could anyone plz help me out..??
谁能帮我一下..??
采纳答案by Damith
To make the MSBuild plugin work, you need to configure the plugin in the Jenkins management screen.
要使 MSBuild 插件工作,您需要在 Jenkins 管理屏幕中配置插件。
NOTE: in the newer Jenkins versions you find the MSBuild configuration in the Global Tool Configuration:
注意:在较新的 Jenkins 版本中,您可以在全局工具配置中找到 MSBuild 配置:


Note the "Name" field, where I've called this particular configuration v4.0.30319. You could call it anything you like, but ideally the name will somehow refer to the version.
请注意“名称”字段,我将这个特定配置称为 v4.0.30319。您可以随意称呼它,但理想情况下,该名称会以某种方式指代版本。
You'll need to refer to this name later in the Jenkins PROJECT that's failing.
您稍后需要在失败的 Jenkins 项目中引用此名称。
Note: The yellow warning implies that the Path to MSBuild field should be populated with a directory name rather than a file name. In practice you do need to enter the filename here too (ie. msbuild.exe) or the build step will fail.
注意:黄色警告暗示 Path to MSBuild 字段应填充目录名而不是文件名。实际上,您也需要在此处输入文件名(即 msbuild.exe),否则构建步骤将失败。
In the Jenkins project that's failing, go to the MSBuild build step.
在失败的 Jenkins 项目中,转到 MSBuild 构建步骤。
The first field in the build step is "MSBuild Version". If you created the build step before configuring any MSBuild versions, the value here will be (default).
构建步骤中的第一个字段是“MSBuild 版本”。如果您在配置任何 MSBuild 版本之前创建了构建步骤,则此处的值将为(默认)。


After configuring one or more MSBuild versions, the drop down will be populated with the available configurations. Select the one you require.
配置一个或多个 MSBuild 版本后,下拉列表将填充可用配置。选择您需要的一种。
You can see here that I've now selected the named configuration that matches the installation above.
您可以在此处看到我现在选择了与上述安装相匹配的命名配置。


回答by fmgp
I think you should set an absolute path for "msbuild.exe" in your Jenkins configuration, for example:
我认为您应该在 Jenkins 配置中为“msbuild.exe”设置绝对路径,例如:
C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe
回答by Mel Padden
You could try executing the
你可以尝试执行
%comspec% /k ""c:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86
command, which will temporarily update your environment path variables to reflect the VS2010 build environment. Execute this before you call MSBUILD and see what happens. I use this in my own build scripts with no issues.
命令,它将临时更新您的环境路径变量以反映 VS2010 构建环境。在调用 MSBUILD 之前执行此操作,看看会发生什么。我在自己的构建脚本中使用它没有任何问题。
Side note; it's very likely counterproductive to have multiple versions of MSBUILD on your PATH. Concentrate on getting one version working and go from there.
边注; 在您的 PATH 上拥有多个版本的 MSBUILD 很可能适得其反。专注于让一个版本工作并从那里开始。
回答by Pavel Zeman
Jenkins | Manage Jenkins | Configure System
scroll down to the MSBuild section and click MSBuild installations
向下滚动到 MSBuild 部分,然后单击 MSBuild 安装
define the full path to msbuild.exe, on my system I have 3.5 and v4.0.30319
定义 msbuild.exe 的完整路径,在我的系统上我有 3.5 和 v4.0.30319
Note - specify the path to 32-bit tools even on a 64-bit system, otherwise you might get an error message:
注意 - 即使在 64 位系统上也要指定 32 位工具的路径,否则您可能会收到错误消息:
Building Windows Phone application using MSBuild 64 bit is not supported.
不支持使用 MSBuild 64 位构建 Windows Phone 应用程序。
So in Jenkins - it could be for example:
所以在詹金斯 - 例如:
Name: Version 3.5
名称:3.5 版
Path: C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe
小路: C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe
Name: Version 4.0
名称:4.0版
Path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe
小路: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe
回答by Ignacio Fernández
You can also add the path where the msbuild.exe is, to the PATH system environment variable of the node (or nodes) that is running that specific job.
您还可以将 msbuild.exe 所在的路径添加到运行该特定作业的节点(或多个节点)的 PATH 系统环境变量中。

