【问题标题】:Jenkin Ms Build Error dot net core applicationJenkins Msbuild 错误 dotnet 核心应用程序
【发布时间】:2020-02-20 03:22:03
【问题描述】:

我正在尝试在 jenkins 中为 dot net core 应用程序执行 ms 构建。

看下面的步骤

  1. nuget restore AddressBroker.API.sln
  2. dotnet build geostan/Xome.Utility.GeoStanGeolocation.csproj
  3. msbuild AddressBrokerNetFramework.Api\\AddressBrokerNetFramework.Api.csproj /p:DeployOnBuild=true /p:PublishProfile=FolderPublish

我收到以下错误

D:\Jenkins\XomeWidgets\feature\XDO-1003\w\sites\AddressBrokerIsolation\AddressBrokerNetFramework.Api\AddressBrokerNetFramework.Api.csproj" (default target) (1) ->
14:40:47    D:\Jenkins\XomeWidgets\feature\XDO-1003\w\sites\AddressBrokerIsolation\AddressBrokerNetFramework.Api\AddressBrokerNetFramework.Api.csproj(182,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

在 jenkins 中在线阅读后,我添加了另一个步骤来解决 msbuild 路径错误,我能够直接从命令提示符执行构建,但是当我通过管道运行时它仍然失败。

  1. %comspec% /k "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\Common7\\Tools\\VsDevCmd.bat"

有人可以帮我找出我需要在管道中添加的内容,请参见下文以使其工作,因为它可以通过 jenkins 服务器中的命令提示符运行,请参见我的管道步骤。

                    bat '''cd sites\\AddressBrokerIsolation
                        nuget restore AddressBroker.API.sln
                        dotnet build geostan/Xome.Utility.GeoStanGeolocation.csproj     
                        %comspec% /k "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\Common7\\Tools\\VsDevCmd.bat"                       
                        msbuild AddressBrokerNetFramework.Api\\AddressBrokerNetFramework.Api.csproj /p:DeployOnBuild=true /p:PublishProfile=FolderPublish           
                        ''' 

【问题讨论】:

  • 嗨,这个问题有什么更新吗?如果问题仍然存在,请随时告诉我 :)

标签: visual-studio jenkins .net-core msbuild


【解决方案1】:

您可以尝试calling the msbuild.exe directly,而不是使用 VsDevCmd.bat。

转到Jenkins -&gt; Manage Jenkins -&gt; Global Tool Configuration -&gt; MSBuild,将路径设置为msbuild:C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe

至于你得到的错误,在我看来有两个可能的原因:

1.在您的构建过程中,msbuild和VS版本被识别为V12.0版本(Visual Studio 2013)。按照我上面的建议直接设置 msbuild 路径可以解决这个问题。

在 Asp.net web 应用程序的项目文件(VS2017)中查看正常内容:

<PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />

如果$(VisualStudioVersion) 被识别为12.0,那么$(VSToolsPath) 将是$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0,然后msbuild 将找不到Microsoft.WebApplication.targets,从而导致此问题。

2.您的 xx.csproj 文件或项目来自 VS2013 中的某些问题。请检查您是否可以在您的enter code herexx.csproj 文件中找到任何v12.0

如果这个项目是VS2017创建的,设置正确的msbuild路径后就不会再出现这个问题了。如果这个项目在VS2013中创建过一次,需要升级xx.csproj文件。希望以上所有帮助:)

【讨论】:

  • 感谢 @Lance Li-MSFT 在我在 jenkins 中进行全局工具配置更改后它工作了
猜你喜欢
  • 2019-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-03
  • 2017-03-06
相关资源
最近更新 更多