i installed the VS2017 build tools with vs_buildtools.exe --add Microsoft.VisualStudio.Workload.MSBuildTools --quiet
but now when I build with the installed MSbuild, passing the /p:DeployOnBuild=true, there seems to be no attempt to do any of the config transformation, aspnet compilation, or deployment that happens when i use the v14.0 tools.
what extra magic incantation do i have to do to make this work?
Make sure that you use the proper MSBuild.exe.
This:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin
Or if IDE (enterprise) installed:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin
If configure an MSBUILD step in a TFS server, set the path of the MSBUILD.exe manualy (Advenced/MSBuild/Specify location):
Using this:
C:\Program Files (x86)\MSBuild\15.0\Bin
will cause that no deployment package created.
Related
I am setting up a new TeamCity build agent. Several build configurations that run perfectly well on the existing agent are failing on the new agent, with errors like this (whitespace added for clarity):
[22:14:32][someproject.vbproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\bin\Microsoft.VisualBasic.CurrentVersion.targets(322, 5):
error MSB4019: The imported project
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\bin\Roslyn\Microsoft.VisualBasic.Core.targets"
was not found.
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
Note the path on line three after "The imported project". The error is correct; the folder does exist but the file does not exist there. However the Microsoft.VisualBasic.Core.targets file does exist at a slightly different path
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Roslyn\Microsoft.VisualBasic.Core.targets
Is there an easy fix for this, perhaps a registry entry telling MSBuild where to look?
Cause
On your machine, there are two copies of VS 2017 installed, Professional edition and the raw Build Tools.
You didn't install VB bits for Professional, while did that for Build Tools.
TeamCity prefers MSBuild from Professional edition.
Combine all above, the issue happened.
Fix
You should either force TeamCity to use MSBuild from Build Tools, or add VB to your VS Pro installation.
Reference
https://blog.lextudio.com/the-rough-history-of-msbuild-cc72a217fa98
I can't build a vs2017 solution from the command line, but I can build from the IDE. Once I've built from the IDE the command line build will work. So the ide is doing something different - what am I missing? Here is what I do for the command line build:
nuget.exe restore mysoln.sln
"E:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe" /m /t:Rebuild /clp:Summary /p:Configuration=Debug /p:Platform="Any CPU" mysoln.sln
The output I get:
"Forms.csproj" (Clean target) (14:3) ->
E:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(126,5): error : The current .NET SDK does not support targeting .NET Standard 2.0. Either target .NET Standard 1.6 or lower, or use a version of the .NET SDK that supports .NET Standard 2.0. [E:\wp\Forms.csproj]
Any ideas how I can make the command line build work?
==============
Update
I tried "E:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe" /m /t:Restore GpsConsole.sln from the command line and it works. But when jenkins runs the exact same command i get the same error
==============
Update 2
The way we got the solution building was :
nuget.exe restore mysoln.sln
"E:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe" /m /t:Restore mysoln.sln
"E:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe" /m /t:Rebuild /clp:Summary /p:Configuration=Debug /p:Platform="Any CPU" mysoln.sln
I suggest you rethink you command-line approach.
You can make your build script independent of Visual Studio installation, make it using MSBuild version you want, and reusable on a build server.
Short plan
Install Visual Studio Build Tools 2017
Find proper MSBuild
Clean solution
Restore packages
Build solution
Details
Using Build Tools will give you independence from Visual Studio installation.
Download Build Tools for Visual Studio 2017 from Visual Studio Downloads page (direct link)
Command-line arguments documented here: Use command-line parameters to install Visual Studio 2017
All workloads and components are listed here: Visual Studio Build Tools 2017 component directory
You can use PowerShell module VSSetup. Download it or install from here: Github: Microsoft/Visual Studio Setup PowerShell Module
Just run MSBulid with clean target
Help nuget.exe to use proper MSBuild
Run MSBuild with build target (you can add additional required parameters)
# 1. Find MS Build
Import-Module $PSScriptRoot\VSSetup\VSSetup.psd1
$msBuildPath = (Get-VSSetupInstance | Select-VSSetupInstance -Version 15.0 -Product Microsoft.VisualStudio.Product.BuildTools).InstallationPath
if ([System.IntPtr]::Size -eq 8)
{
$global:msbuildPath = Join-Path $msBuildPath 'MSBuild\15.0\Bin\amd64'
}
else
{
$global:msbuildPath = Join-Path $msBuildPath 'MSBuild\15.0\Bin'
}
Write-Output "Using MSBuild from $global:msbuildPath"
Write-Output "MSBuild /version"
$msbuild = Join-Path $global:msbuildPath msbuild
& $msbuild /version
# 2. Clean
& $msbuild "$sln_file" /t:Clean /v:q /nologo
# 3. Restore
$nuget = Join-Path $PSScriptRoot "\.nuget\nuget.exe"
& $nuget restore -MSBuildPath $global:msbuildPath
# 4. Build
& $msbuild "$sln_file" /t:Build /v:q /nologo
I believe your visual studio does have the .net core 2.0 SDK installed, since it is able to build your .net standard 2.0 solution.
But, nuget restore is pointing to an sdk inside the visual studio directory (one of a few that visual studio can use, but not where .net core 2.0 sdk installs to by default).
Your .net core 2.0 sdk is likely located in C:\...\dotnet\...
You'll want to have nuget restore use the msbuild located inside that directory, rather than the one within the visual studio directory.
How do I target MSBuild 15.0 on my server? I have 15.0 installed on the server but my project is still building with 14.0. I know that Microsoft has made some changes to the directory locations and no longer uses the registry values with 15.0.
I found 15.0 installed in the following locations:
C:\Program Files (x86)\MSBuild\15.0
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild
And I have the .Net framework 4.6.2 installed here:
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319"
Thanks!
Product: BuildMaster
Version: 5.7.2
Update 1:
Responding to #emiel-koning, I tried to specify $MSBuildToolsPath in the build step using:
set $MSBuildToolsPath = C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin;
But I get this error:
error MSB4226: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" was not found. Also, tried to find "WebApplications\Microsoft.WebApplication.targets" in the fallback search path(s) for $(VSToolsPath) - "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0" . These search paths are defined in "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe.Config". Confirm that the path in the declaration is correct, and that the file exists on disk in one of the search paths.
Update 2:
Could I be missing something installed on my build server? I installed Visual Studio Build Tools which gave me the MSBuild 15.0 but not the WebApplication.targets file from the error above
SOLUTION
I fix my issues by also installing "Web development build tools" component. I also set the $MSBuildToolsPath at the server level until I can roll out the new MSBuild globally.
In general, this is handled by the ToolsVersion attribute of the project file. This should be what is used if the below configuration is not specified.
In BuildMaster specifically, you can override this value per-server on the Administration > BuildMaster Extensions > Windows SDK > Configuration tab. Click on $MSBuildToolsPath (and optionally override at a specific scope) with a value of C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin
Response to Updates #1 & #2:
First, don't set that variable in the plan itself (otherwise you'd have to set it in every plan). Set it in the manner I described above. Personally, I always specify its value at the server level since each server may have it installed in a different location.
As for Microsoft.WebApplication.targets, I think the only supported method of building web application projects is to have Visual Studio installed on the build server; though in the past I've just copied the targets from my local installation (C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications) into the path that MSBuild is expecting them to be.
Can you use $MSBuildToolsPath to specify the correct path to MSBuild?
I'm trying to restore NuGet packages for a .NET Core solution using NuGet Installer TeamCity build step. The 'MSBuild auto-detection' chooses MSBuild v4.0 instead of v15.0 which is required for .NET Core projects:
[15:41:53][restore] Starting NuGet.exe 4.1.0.2450 from C:\TeamCity\buildAgent\tools\NuGet.CommandLine.4.1.0\tools\NuGet.exe
[15:41:53][restore] MSBuild auto-detection: using msbuild version '4.0' from 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319'.
[15:41:53][restore] Nothing to do. None of the projects in this solution specify any packages for NuGet to restore.
[15:41:53][restore] Process exited with code 0
This leads to the compilation error in the 'MSBuild' TeamCity step that runs after the package restoring:
Assets file 'C:\TeamCity\...\MyProj\obj\project.assets.json' not found.
Run a NuGet package restore to generate this file.
For the 'MSBuild' TeamCity step I choose the MSBuildTools version manually as described in this SO answer:
But I didn't manage to find the similar setting for the 'NuGet Installer' step. Am I missing something?
I managed to overcome this specifying the -MSBuildPath command line parameter:
As #PeterLai said, nuget version is the right place to look.
So, because I had the same problem here, I updated Nuget inside Teamcity / Administration / Integrations / Tools.
I moved from 3.4.3 to 4.6.2, and just rebuild.
Now it finds my visual studio 2017 msbuild, version 15!
BEFORE:
NuGet command: D:\...\NuGet.CommandLine.3.4.3\tools\NuGet.exe restore D:\...\proj.sln
...
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
AFTER:
NuGet command: D:\...\NuGet.CommandLine.4.6.2\tools\NuGet.exe restore D:\...\proj.sln
...
MSBuild auto-detection: using msbuild version '15.5.180.51428' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin'.
2 things,
It might be because it's running it from the folder Starting NuGet.exe 4.1.0.2450 from C:\TeamCity\buildAgent\tools\NuGet.CommandLine.4.1.0\tools\NuGet.exe, and not in the source code directory as you'd expect.
Have you got a packages.config file in your project?
If you are only using .NET Core / .NET Standard projects ("SDK-based" csproj), you don't need to restore with nuget.exe but can create an msbuild invocation that calls the Restore target:
msbuild /t:Restore the.sln
This also applies to non-core/standard projects (classic csproj) if they use the PackageReference package management format:
I have a .vbproj which is a VB.NET web application project. I can build the solution that contains this project and then right click on the project and publish locally. No issues from with VS 2013 professional update 3.
I am trying to build this solution and then publish the project outside of VS using the msbuild plugin from within Jenkins CI.
The project does not get published as it says it is skipping unpublishable project.
The command and it output is as follows:
Executing the command
cmd.exe /C C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
/t:Publish /p:VisualStudioVersion=12.0 /p:OutDir=C:/temp/eric
StarWebPortal/StarWebPortal/StarWebPortal.vbproj && exit
%%ERRORLEVEL%% from C:\Tools\Jenkins\jobs\STAR-dev_POC\workspace
[workspace] $ cmd.exe /C
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe /t:Publish
/p:VisualStudioVersion=12.0 /p:OutDir=C:/temp/eric
StarWebPortal/StarWebPortal/StarWebPortal.vbproj && exit
%%ERRORLEVEL%% Microsoft (R) Build Engine version 4.0.30319.18408
[Microsoft .NET Framework, version 4.0.30319.18444] Copyright (C)
Microsoft Corporation. All rights reserved.
Build started 8/22/2014 11:46:51 AM. The target "MvcBuildViews" listed
in a BeforeTargets attribute at "C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets
(840,131)" does not exist in the project, and will be ignored. Project
"C:\Tools\Jenkins\jobs\STAR-dev_POC\workspace\StarWebPortal\StarWebPortal\StarWebPortal.vbproj"
on node 1 (Publish target(s)).
_DeploymentUnpublishable: Skipping unpublishable project. Done Building Project
"C:\Tools\Jenkins\jobs\STAR-dev_POC\workspace\StarWebPortal\StarWebPortal\StarWebPortal.vbproj"
(Publish target(s)).
Any idea why it works from within VS and not from the msbuild command line?
You have to configure Jenkins to pass two additional arguments to MsBuild.exe which are /p:DeployOnBuild=true and /p:PublishProfile=your_publish_profile.pubxml.
The command should be like msbuild your_vb_project.vbproj /p:DeployOnBuild=true /p:PublishProfile=publish_profile.pubxml You don't need to specified path to publish_profile.pubxml as long as it's under the same directory with your vbproj.
As of Visual Studio 2013, MSBuild is now a separate component from the .NET Framework and is included in the install with VS. It is also available as a separate download for build servers. It looks like you are using the "old" v4.0 MSBuild path. You need to use the new MSBuild path which is something like C:\Program Files(x86)\MSBuild\12.0\bin. You need to configure the Jenkins MSBuild plugin to use this path.