Reputation: 351
I am trying to perform ms build for dot net core application in jenkins.
See below steps
nuget restore AddressBroker.API.sln
dotnet build geostan/Xome.Utility.GeoStanGeolocation.csproj
msbuild AddressBrokerNetFramework.Api\\AddressBrokerNetFramework.Api.csproj /p:DeployOnBuild=true /p:PublishProfile=FolderPublish
i get the following below error
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.
In jenkins after reading online i added another step to resolve msbuild path error i was able to perform the build directly from command prompt but it still fails when i run through pipeline.
%comspec% /k "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\Common7\\Tools\\VsDevCmd.bat"
Can someone please helpme out what i need to add in my pipeline see below to make it work because it works from command promt in the jenkins server see below my pipeline steps.
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
'''
Upvotes: 0
Views: 1456
Reputation: 28196
You can try calling the msbuild.exe directly instead of using the VsDevCmd.bat.
Go Jenkins -> Manage Jenkins -> Global Tool Configuration -> MSBuild
, set the path to msbuild: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe
As for the error you got, in my opinion there're two possible causes:
1.In your build process, the msbuild and VS version are recognized as V12.0 version(Visual Studio 2013). Setting the msbuild path directly as what I suggest above can resolve this issue.
See normal content in Asp.net web app's project file(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)' != ''" />
If the $(VisualStudioVersion)
is recognized as 12.0
, then the $(VSToolsPath)
would be $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0
, then msbuild won't find the Microsoft.WebApplication.targets
, which caused this issue.
2.Something broken in your xx.csproj
file or the project comes from VS2013. Please check if you can find any v12.0
in your enter code here
xx.csproj file.
If this project is created by VS2017, this issue won't occur any more after you set the correct msbuild path. If this project is created in VS2013 once, you need to upgrade the xx.csproj
file. Hope all above helps :)
Upvotes: 1