Running vs2017 DevEnv from command line with VS2017 Installer Projects - jenkins

I have inherited a bunch of VS2010 (argh!) installer projects (.vdproj) that install some Win Services
Ofcourse in VS2017 those don't exist anymore but the extension 'VS2017 Installer Projects' works great. I can just open them fine and build, which produces the msi files.
However this needs to be done on the Jenkins machine (running Windows 7) as well. So I installed VS2017 on the Jenkins machine with the Project Installer extension and tried to first run the project from the IDE. Works great. Produces the .msi without problem.
Then I tried to run it from a command line:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe"
D:\ServiceInstaller\xxxServiceInstaller.vdproj /build
And it does NOT produce anything. Am I trying to do something that is not possible?
There are all kinds of long term solutions of course such as TopShelf, AdvancedInstaller, WIX etc with nice Jenkins plugins but for now it would be nice if I could make this work.

I've made following batch file to call with solution file parameter:
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat"
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\VSI\DisableOutOfProcBuild\DisableOutOfProcBuild.exe"
devenv /rebuild "Release|Win32" %1
Also make sure that in Visual Studio Configuration Manager Setup build is enabled.

Related

Location of nmake in VS2019 is not generic. Or am I missing something?

I am creating a generic script to deploy on the build server to build our project using VS 2019. The location of nmake in VS 2019 is at: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\bin. The inclusion of numbers like 14.29.30133 doesn't allow the script to be very generic.
In the earlier generations of VS, nmake paths were like: C:\Program Files\Microsoft Visual Studio 10.0\Vc\bin or C:\Program Files (x86)\Microsoft Visual Studio 11.0\Vc\bin
Maybe I installed MSVC incorrectly? Any help is appreciated. TIA.
You installed MSVC correctly, and yes, this can cause some headaches, because the version number in the folder name changes with every new minor release of VS 2019.
To resolve this, use this command line snippet for getting the path to the latest installed nmake.exe into the variable %NMAKE%:
set VSPATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional
for /f %%i in ('dir "%VSPATH%\VC\Tools\MSVC" /b') do set VCTOOLSVERSION=%%i
set NMAKE="%VSPATH%\VC\Tools\MSVC\%VCTOOLSVERSION%\bin\HostX86\x86\nmake.exe"
This works for all intermediate versions of Visual Studio 2019 I tested it with.

.Net-Core Proj - MSBuild failing to copy to output folder

Trying to build to .NET-Core Project from TFS, the build is failing because the following command`s not working, failing to copy built files to output folder. The command is working fine for a .Net Framework project, not working only for .Net Core Project. Kindly check.
It works fine with basic command:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin>MSBuild.exe "C:\TFSFolder\Builds\GUID\DotnetCoreProject.sln" /p:OutDir="C:\TFSFolder\Builds\39\b\DotnetCoreProject\\"
Non-working Command:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin>MSBuild.exe "C:\TFSFolder\Builds\GUID\DotnetCoreProject.sln" /nologo /nr:false /t:"Clean" /dl:CentralLogger,"C:\TFSFolder\Builds\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.126.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=2c81e6a8-374d-4a65-91ba-418b04505e77|SolutionDir=C:\TFSFolder\Builds\GUID\"*ForwardingLogger,"C:\TFSFolder\Builds\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.126.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:OutDir="C:\TFSFolder\Builds\39\b\DotnetCoreProject\\" /t:Restore /p:platform="any cpu" /p:configuration="release" /p:VisualStudioVersion="15.0" /p:_MSDeployUserAgent="TFS_fa1cf861-541e-47b2-b0f3-8c684de5500a_build_22138_1486294"
It just need to copy built files to the output folder path mentioned. I could only guess that the dll mentioned isnt supported, kindly check and help.
It looks like you are only restoring and cleaning the project because you specify /t:Clean and /t:Restore.
Use -restore -t:Rebuild instead.
Also note that you normally don't want the output directory contents of a .NET Core project for deployment but rather its publish output. For this use the Publish target on the project instead:
-restore -t:Publish theproject.csproj -p:PublishDir=artifact\location

VCVARSALL.BAT for Visual studio 2019

What is the location of vcvarsall.bat file for Visual Studio 2019 (Preview and future release as well)?
Seems it is different from VS 2017 "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat"
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat"
As it turned out the path is very similar, just without "Community" part:
For VS2019:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Auxiliary\Build\vcvarsall.bat
For VS2022 since the toolchain now is 64-bit:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat
If after installing the "Build Tools for Visual Studio 2019" and doing all that was recommended in the other answers, you still can't find the the file in the location mentioned (no Build folder inside Auxiliary) make sure you
Install "Desktop Development With C++ Workload"
because vcvarsall.bat is part of C++ workload.
(In VS, go Tools menu -> Get Tools and Features -> Install the Desktop Development With C++ workload)
You need to install the "Build Tools for Visual Studio 2019" which can be found here.
See the explanation:
You can build C and C++ applications on the command line by using tools that are included in Visual Studio. The Microsoft C++ (MSVC) compiler toolset is also downloadable as a standalone package from the Visual Studio downloads page. It's part of the Build Tools for Visual Studio package. You can choose to download only the tools you need for C++ development.
If you are using it in the pre-build event, you can execute the vcvars32.bat to set the environment variable VCINSTALLDIR and get rid of the Visual Studio version:
call "$(DevEnvDir)....\VC\Auxiliary\Build\vcvars32.bat"
Then
"%VCINSTALLDIR%\Auxiliary\Build\vcvarsall.bat"
Note:
-In my tests, the variable VCINSTALLDIR has value only after executing the vcvars32.bat
-As Wei Yang said you need to install "Build Tools for Visual Studio 2019", it can be installed using Visual Studio Installer.
I felt free to add a possible solution.
1.) Open the Developer Command Prompt for your wanted VS if you have more than one installed. BTW this lets you work with TFS tool tf if you need it.
2.) Add in your make script the following code at the concerning location:
for /f "delims=" %%d in ('dir /s /b %VSINSTALLDIR%\vcvarsall.bat"') do #set myVCVARSALL=%%d
if not defined myVCVARSALL exit 1
call %myVCVARSALL%
Hope that helps to find this file for the wanted VS version. It results in different files for different installations.
I needed to install and build some older build tools for windows. So, I had to set the location.
The location is C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build
If you haven't installed the "Build Tools for Visual Studio 2019", you can do so from https://visualstudio.microsoft.com/downloads/.
Once this is done, the correct path for running vcvarsall.bat is;
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat"
For VS 2019 Professional, it is "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsall.bat"
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat this is the location.

TFS build dosn't complete correctly when I use c# 7 feature in my code

I've installed TFS (version 15.112.26307.0) on windows server 2012 R2. all team members use VS2017 to coding. I've created an agent (I've tried versions vsts-agent-win7-x64-2.112.0, 2.117.0 ,2.140.0)and set it's MSBuild version to MSBuild15.0 :
MSBuild15.0 has already installed on the server :
But when we use c# 7 features in our code(like "int out x") building code via TFS raise error as below (it use MSBuild14.0 to build our code, why?)
My agent capabalities is not correct :
Use the Visual Studio Build task. It allows you to specify the Visual Studio version used to run builds.
Seems the capabilities cannot be detected by the agent. If you have installed the VS 2017 on the build agent server, then you can try to restart the agent service to check if that works.
If that still not work, you could try below things:
Add the capabilities manually.
The path of them are(Enterprise version for example):
VisualStudio_15.0 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\
VisualStudio_IDE_15.0 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\
MSBuild_15.0 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\
MSBuild_15.0_x64 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\
VSTest C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common\IDE\CommonExtensions\Microsoft\TestWindow
Specify the path to Msbuild 15.0:

Building UWP app in command line (using MSBUILD)

I am trying to build UWP app (targeting 16299) from command line from Jenkins setup.
The system has only VS build tools 2017.
used this command to build
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe" /t:Rebuild /p:Configuration=Release;AppxBundle=Always;AppxBundlePlatforms="x86\x64\ARM" /p:BuildAppxUploadPackageForUap=true SOLUTION_FILE.sln
error MSB4226: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\WindowsXaml\v15.0\Microsoft.Windows.UI.Xaml.CSharp.targets" was not found. Also, tried to find "Microsoft\WindowsXaml\v15.0\Microsoft.Windows.UI.Xaml.CSharp.targets" in the fallback search path(s) for $(MSBuildExtensionsPath) - "C:\Program Files (x86)\MSBuild" . 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.
Another issue found is nuget is not restoring any package, so updated nuget to 4.4.1 then I got the error
MSBuild auto-detection: using msbuild version '15.5.180.51428' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin'.
Nothing to do. None of the projects in this solution specify any packages for NuGet to restore.
same issue with nuget 4.6.0 also
I tried by adding following in project file
<PropertyGroup>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle> </PropertyGroup>
same issue with msbuild and nuget, anyone succeed in building UWP in Jenkins?
Update 05-01-2015
Followed instruction according to answer.
Copied NuGet folder
Copied the "WindowsXaml" folder.
Used MSbuild restore instead of Nuget restore to fix msbuild trying to find packages in "C:\WINDOWS\system32\config\systemprofile.nuget\packages\"
With all these changes no more issues in build,
But the appx bundle is not present. may be individual appx for x86/x64/ARM has to be created and then some kind of merging i s required.
so need further investigations
From the directory path that you have for MSBuild, I see that you may have installed MSBuildTools installer instead of the community, professional,... editions.
I tried that before and found that it's incomplete and doesn't have all dependencies for building Uwp tools, take a look at some of the comments here about the issues.
First Workaround: You can install Uwp Workload from VS Community or Professional as it has all dependencies, till Microsoft fix the issues in BuildTools installer.
Bonus: if you want to run the installer from command line, you can compose command line like that:
vs_installer.exe --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools" ^
--add Microsoft.VisualStudio.Workload.Universal ^
--add Microsoft.VisualStudio.Component.Windows10SDK.14393 ^
--add Microsoft.Component.MSBuild ^
--passive --wait --norestart
The longer workaround, I managed to install other dependencies but I believe it's kind of hassle if you are automating this installation, snippets from this article
Copy the Sdks folder from a machine that has VS2017 installed at:
c:\Program Files(x86)\Visual Studio\2017\Professional\Build MSBuild\Sdks
to your build machine at:
c:\Program Files(x86)\Visual Studio\2017\Build Tools\MSBuild\Sdks
And for the nuggets issue:
Copying the NuGet import files will do the tr Again, from a machine
with VS2017, copy the following folder: C:\Program Files
(x86)\Microsoft Visual
Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\NuGet
to your build machine at: C:\Program Files (x86)\Microsoft Visual
Studio\2017\BuildTools\Common7\IDE\CommonExtensions\Microsoft\NuGet
Note: If you come by this later and found that Microsoft fixed the issues related to Uwp in MSBuildTools installer, please leave a comment about it in this answer to update it.

Resources