在Jenkins中构建后,msbuild.exe无法识别命令

时间:2013-09-03 09:15:29

标签: c# .net msbuild jenkins

1。共享违规行为

跟随http://programmaticponderings.wordpress.com/2012/08/08/convert-vs-2010-database-project-to-ssdt-and-automate-publishing-with-jenkins-part-33/

之后
    echo 'Copying Adventure Works Solution to Jenkins workspace...'
xcopy /s /E /H /Y /R "C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3" "C:\Program Files (x86)\Jenkins\jobs\testing003\workspace" 

echo 'Deleting artifacts from previous builds...'
del "%WORKSPACE%\*_publish.zip" /F /Q

2.使用MS build

构建ms项目

添加C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \环境变量路径后 并在Jenkins中设置构建C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ MSbuild.exe

'C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.sqlproj' /p:Configuration=Database3 /p:Platform=AnyCPU /t:Build;Publish /p:SqlPublishProfilePath='C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.publish.xml' /p:UpdateDatabase=False


Executing the command cmd.exe /C msbuild.exe "C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.sqlproj" /p:Configuration=Database3 /p:Platform=AnyCPU /t:Build;Publish "/p:SqlPublishProfilePath=C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.publish.xml" /p:UpdateDatabase=False C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe && exit %%ERRORLEVEL%% from C:\Program Files (x86)\Jenkins\jobs\testing003\workspace
[workspace] $ cmd.exe /C msbuild.exe "C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.sqlproj" /p:Configuration=Database3 /p:Platform=AnyCPU /t:Build;Publish "/p:SqlPublishProfilePath=C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.publish.xml" /p:UpdateDatabase=False C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe && exit %%ERRORLEVEL%%
'msbuild.exe' is not recognized as an internal or external command,


C:\Users\User2>cmd.exe /C msbuild.exe "C:\Users\LAB-User2\Documents\Visual S
tudio 2012\Projects\Database3\Database3.sqlproj" /p:Configuration=Database3 /p:P
latform=AnyCPU /t:Build;Publish "/p:SqlPublishProfilePath=C:\Users\LAB-User2\Doc
uments\Visual Studio 2012\Projects\Database3\Database3.publish.xml" /p:UpdateDat
abase=False C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe && exit %%
ERRORLEVEL%% from C:\Program Files (x86)\Jenkins\jobs\testing003\workspace
Microsoft (R) Build Engine version 4.0.30319.17929
[Microsoft .NET Framework, version 4.0.30319.18034]
Copyright (C) Microsoft Corporation. All rights reserved.

MSBUILD : error MSB1008: Only one project can be specified.
Switch: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe

For switch syntax, type "MSBuild /help"

更新 完整的控制台输出

Started by user anonymous
Building in workspace C:\Program Files (x86)\Jenkins\jobs\testing003\workspace
[workspace] $ cmd /c call C:\Windows\TEMP\hudson1045566609826009314.bat

C:\Program Files (x86)\Jenkins\jobs\testing003\workspace>echo 'Copying Adventure Works Solution to Jenkins workspace...' 
'Copying Adventure Works Solution to Jenkins workspace...'

C:\Program Files (x86)\Jenkins\jobs\testing003\workspace>xcopy /s /E /H /Y /R "C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3" "C:\Program Files (x86)\Jenkins\jobs\testing003\workspace"  
C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.sln
C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.v11.suo
C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\excludefiles.txt
C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3\Database3.dbmdl
Sharing violation

C:\Program Files (x86)\Jenkins\jobs\testing003\workspace>echo 'Deleting artifacts from previous builds...' 
'Deleting artifacts from previous builds...'

C:\Program Files (x86)\Jenkins\jobs\testing003\workspace>del "C:\Program Files (x86)\Jenkins\jobs\testing003\workspace\*_publish.zip" /F /Q 
Could Not Find C:\Program Files (x86)\Jenkins\jobs\testing003\workspace\*_publish.zip

C:\Program Files (x86)\Jenkins\jobs\testing003\workspace>exit 0 
Path To MSBuild.exe: msbuild.exe
Executing the command cmd.exe /C msbuild.exe "C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.sqlproj" /p:Configuration=Database3 /p:Platform=AnyCPU /t:Build;Publish "/p:SqlPublishProfilePath=C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.publish.xml" /p:UpdateDatabase=False C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe && exit %%ERRORLEVEL%% from C:\Program Files (x86)\Jenkins\jobs\testing003\workspace
[workspace] $ cmd.exe /C msbuild.exe "C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.sqlproj" /p:Configuration=Database3 /p:Platform=AnyCPU /t:Build;Publish "/p:SqlPublishProfilePath=C:\Users\LAB-User2\Documents\Visual Studio 2012\Projects\Database3\Database3.publish.xml" /p:UpdateDatabase=False C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe && 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 build as failure
Finished: FAILURE

enter image description here

5 个答案:

答案 0 :(得分:42)

如果要使用Jenkins构建.NET项目,请执行以下步骤:

  1. 安装MsBuild Plugin

  2. 转到Jenkins -> Manage Jenkins -> Configure System (在较新版本上:Jenkins -> Manage Jenkins -> Global Tool Configuration -> MSBuildmsbuild

  3. 在MSBuild部分中,点击 AddMsBuild 按钮并指定详细信息:

    • 名称:MsBuild的名称
    • MsBuild的路径:指定msbuild.exe的路径。示例:C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe
  4. 保存并应用更改。

  5. 选择你的工作。

  6. 选择添加构建步骤

  7. 选择MsBuild版本。

  8. 指定项目文件的路径(.csproj或.sln)

  9. msbuild in project

    1. 构建您的项目。

答案 1 :(得分:7)

对于较新版本的Jenkins,此选项可在此部分下找到..

Manage Jenkins -> Global Tool Configuration ->  MSBuild

从这个回答:https://stackoverflow.com/a/37939483/2880781

答案 2 :(得分:1)

对于最新版本的jenkins(3.0),您必须在Tools>Manage Jenkins菜单中配置MSBuild。在这里命名一份工作,例如:msbuild。 完成后,继续工作。在MSBuild模块下选择构建(在本例中为msbuild),然后启动作业。你应该好好去。

答案 3 :(得分:0)

在作业配置中选择MSBuild版本,并在您的jenkins'中配置MSBuild版本。配置系统。

答案 4 :(得分:0)

  1. 在服务器上安装Visual Studio
  2. 登录到您的Jenkins
  3. 安装MSBuild插件
  4. 转到Jenkins>管理Jenkins>全局工具配置
  5. 单击“ MSBuild安装”
  6. 点击添加MSBuild
  7. 名称:Visual Studio(即Visual Studio 2019社区)
  8. MSBuild的路径(即C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Community \ MSBuild \ Current \ Bin) enter image description here
  9. 点击保存
  10. 转到您的Jenkins项目
  11. 点击配置
  12. 开始构建
  13. 选择您的MSBuild版本
  14. 输入Solutin文件的名称 enter image description here