How to use MSBuild to build a Visual Studio Setup Project - visual-studio-2010

I am trying to use MSBuild to build a Visual Studio Setup Project using the article below:
http://msdn.microsoft.com/en-us/library/ms404859.aspx
https://web.archive.org/web/20090218033835/msdn.microsoft.com/en-us/library/ms404859.aspx
I have followed all the steps mentioned in the article above with the exception of not using TFS in this case.
Instead of using the TFS option, I am trying to create a Demo.proj file and have included the below details:
** - Demo.proj**
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="AfterCompile">
<Exec Command=""$(ProgramFiles)\Microsoft Visual Studio 9.0\Common7\IDE\devenv" "C:\Users\sapatro\Documents\visual studio 2010\Projects\HelloWorldTest\HelloWorldTestInstaller\HelloWorldTestInstaller.vdproj" /Build "Debug|Any CPU""/>
<Copy SourceFiles="C:\Users\sapatro\Documents\visual studio 2010\Projects\HelloWorldTest\HelloWorldTestInstaller\Debug\HelloWorldTestInstaller.msi; C:\Users\sapatro\Documents\visual studio 2010\Projects\HelloWorldTest\HelloWorldTestInstaller\Debug\setup.exe" DestinationFolder="$(OutDir)" />
</Target>
</Project>
now when I trying to cmd prompt and trying the following command:
msbuild DemoBuild.proj /target:AfterCompile
I am getting the following error:
Build FAILED.
"C:\xxxxxxxxx\Documents\Visual Studio 2010\Projects\HelloWorldTest\DemoBuild.proj" (default target) (1) ->
(AfterCompile target) ->
C:\xxxxxxxxx\Visual Studio 2010\Projects\HelloWorldTest\DemoBuild.proj(4,5): error MSB3073: The command ""C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv" "C:\xxxxxxxxx\Documents\visual studio 2010\Projects\HelloWorldTest\HelloWorldTestInstaller\HelloWorldTestInstaller.vdproj" /Build "Debug|Any CPU"" exited with code 1.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:01.25
Can anyone help me to resolve this issue.
Thanks & Regards,
Santosh Kumar Patro

This works for me:
<Exec Command=""$(ProgramFiles)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.com" your.vdproj /build "Debug|AnyCPU""/>
You don't need the space in any cpu and you need to call devenv.com, also assuming you have those build configuration existing?

James' answer helped me but I still got an error stating An error occurred while validating.
I had to also do this and finally got it working. For VS2015, add the registry key HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0_Config\MSBuild\EnableOutOfProcBuild and set the value to 0.

Related

Visual Studio 2017 MSBuild issue

I am trying to publish a Visual stuido Project from another Project, to do this I have created a bat file which runs my MSBuild file. If you run this outside of Visual Studio it works correctly but when i tried to add it to Visual Studio's prebuild scripts it does not publish. I am getting this warning -
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3247: Found confl
icts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select
it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the a
pplication configuration file
My MSBuild file:
<Target Name="BeforeBuild">
<MSBuild
Projects="E:\Development\alyz\myAPI\View.API.sln"
Targets="View_API_Search"
Properties="DeployOnBuild=true;Configuration=Release;PublishProfile=InstallerPublish;WebPublishMethod=FileSystem;PublishURL=E:\Temp\installertemp\SearchAPI" />
</Target>
Visual Studio is saying that my project has built correctly but i can't work out why it's not publishing, any ideas?
Visual Studio is saying that my project has built correctly but i can't work out why it's not publishing, any ideas?
You can use another solution for this issue. Following is my publish target, you can check it:
<Target Name="BeforeBuild">
<Exec Command=""<YourMSBuild.exePath>\msbuild.exe" "<YourSolutionPath>\View.API.sln" /p:DeployOnBuild=true /p:PublishProfile=InstallerPublish.pubxml /p:Configuration=Release /p:PublishURL=E:\Temp\installertemp\SearchAPI"></Exec>
</Target>
With this target, the project/solution will be build and published when you build the project.
Hope this helps.

DevEnvDir in VS2017 points to VS2015

In my extension project file I'v set Start Action to start Visual Studio by setting StartPrograms in my project file (.vbproj if that matters)
<StartPrograms>$(DevEnvDir)devenv.exe</StartPrograms>
The problem is that when the project is open in VS2017 it opens VS2015 and in project properties I see:
Is there something wrong with my project? Or do I undersant DevEnvDir wrong way?
DevEnvDir in VS2017 points to VS2015
That because you set the Start external program is Visual Studio 2015. And this info stored in the .csproj.user file. If open that .csproj.user file in the same folder as project file, you will find following:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartAction>Program</StartAction>
<StartProgram>C:\Program Files %28x86%29\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe</StartProgram>
</PropertyGroup>
</Project>
So, even if you specify the StartPrograms in the project file, but specify Start external program in the project property will overwrite it.
To resolve this issue, you should specify Start external program as Visual Studio 2017:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe
Hope this helps.

Visual Studio 2017 extension - VSToolsPath not working

I'm updating an old Visual Studio extension for VS 2017. It compiles fine from Visual Studio and msbuild in debug and release on my local computer.
This is the msbuild command line I am using:
msbuild VxCop.sln /p:ToolsHome=C:\ProgramData\chocolatey\bin /p:Configuration=Release /p:Platform="Any CPU"
However, on the build machine (TFS Build 2010) calling msbuild.exe with the same command line it fails with this error
In order to fix this I am trying to specify VSToolsPath. I've tried various things such as altering the VSToolsPath entry in the .csproj (which seems to not be taken into account since doing this had no effect) and also passing it on the command line:
msbuild VxCop.sln /p:ToolsHome=C:\ProgramData\chocolatey\bin /p:Configuration=Release /p:Platform="Any CPU" /p:VSToolsPath=Packages\Microsoft.VSSDK.BuildTools.15.1.192\tools\
This causes a very strange error:
CopyFilesToOutputDirectory:
Copying file from "obj\Release\SymCop.dll" to "bin\Release\SymCop.dll".
SymCop -> H:\src\tools\VisualStudioExtensions\Main\VxCop\source\SymCop\bin\Release\SymCop.dll
Copying file from "obj\Release\SymCop.pdb" to "bin\Release\SymCop.pdb".
Done Building Project "H:\src\tools\VisualStudioExtensions\Main\VxCop\source\SymCop\SymCop.csproj" (default targets).
Done Building Project "H:\src\tools\VisualStudioExtensions\Main\VxCop\VxCop.sln" (Build target(s)) -- FAILED.
Done Building Project "H:\src\tools\VisualStudioExtensions\Main\VxCop\build.proj" (default targets) -- FAILED.
Build FAILED.
0 Warning(s)
0 Error(s)
The actual extension project isn't appearing in the log at all, and there's no, y'know, errors. But the build returns as failed, the return code is non-zero, and the vsix project seems to not be built (its output is missing)
Hopefully someone has some suggestions
Thanks
Edit:
For those reading this in the future, the problem seemed to be that there was an <Import> further down in the same file which didn't care about my update to $(VSToolsPath).
Changing that import fixed it:
<Import Project="$(SolutionDir)\packages\Microsoft.VSSDK.BuildTools.15.1.192\tools\VSSDK\Microsoft.VsSDK.targets"
/>
Visual Studio 2017 extension - VSToolsPath not working
I got the same result as you based on your scripts. After installed the NuGet package Microsoft.VSSDK.BuildTools to the project, the Microsoft.VSSDK.BuildTools.props will be imported in to project file, open the project file, you can find below Import:
<Import Project="..\packages\Microsoft.VSSDK.BuildTools.15.1.192\build\Microsoft.VSSDK.BuildTools.props" Condition="Exists('..\packages\Microsoft.VSSDK.BuildTools.15.1.192\build\Microsoft.VSSDK.BuildTools.props')" />
Then open this props file, you can notice below scripts snippet:
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="VSSDK_NuGet_Configuration">
<ThisPackageDirectory>$(MSBuildThisFileDirectory)..\</ThisPackageDirectory>
<VSToolsPath>$(ThisPackageDirectory)\tools</VSToolsPath>
<VsSDKInstall>$(VSToolsPath)\VSSDK</VsSDKInstall>
<VsSDKIncludes>$(VsSDKInstall)\inc</VsSDKIncludes>
<VsSDKToolsPath>$(VsSDKInstall)\bin</VsSDKToolsPath>
</PropertyGroup>
</Project>
In this case, NuGet package override the value VSToolsPath with $(ThisPackageDirectory)\tools. So MSBuild will skip set the value setting in the next step in the project file:
<PropertyGroup>
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
Because NuGet have already set the value $(VSToolsPath), the value of Condition="'$(VSToolsPath)' == ''" would be False. In addition, you can add a target to check if the value is set, like:
<Target Name="CheckVSToolsPath" BeforeTargets="Build">
<Message Text="$(VSToolsPath)"></Message>
</Target>
You will find this value is set to:
C:\Users\Admin\Documents\Visual Studio 2017\Projects\VSIXProject2\packages\Microsoft.VSSDK.BuildTools.15.1.192\build\..\\tools
Summary above, the value of VSToolsPath was imported correctly, we do not need to passing it on the command line.
After in-depth investigation, I found the reason for the previous error "MSB4226: The imported project "(...)\VSSDK\Microsoft.VsSDK.targets" was not found." is that the MSBuild property of "VisualStudioVersion" not be set on the build server.
See below link for detail info Building a VSIX extension with the Visual Studio 2017 Build Tools:
something that a machine with the full Visual Studio 2017 does and that a machine with the Build Tools 2017 does if you open a developer command prompt. Since I was not using it, I passed it as a parameter to the MSBuild script. It can be defined too inside the .csproj file, something that previous Visual Studio versions did automatically but recent versions don’t.
So to resolve the error "MSBuild4226", you should pass the visual studio version on command line:
msbuild VxCop.sln /p:ToolsHome=C:\ProgramData\chocolatey\bin /p:Configuration=Release /p:Platform="Any CPU" /p:VisualStudioVersion=15.0
After using this command line, the error MSBuild 4226 was resolved.
Hope this helps.
I resolved this problem in VS 2019 by https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#generatepathproperty
<ItemGroup>
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="16.10.1055">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<Import Project="$(PkgMicrosoft_VSSDK_BuildTools)\tools\vssdk\Microsoft.VsSDK.targets" />

devenv.com won't start without a desktop session

I'm setting up a Jenkins job for a Windows 10 application.
I need to compile one of the four projects inside the solution with devenv.com executable because it is a project with .vdproj extension (setup project).
The other projects are built successfully with MSBuild without any problem.
The Jenkins job ends successfully when I'm logged in as root on a Jenkins target node, but, fails when I run the job from Jenkins and I'm not logged in.
Need your help or workaround to solve the issue.
PS: we are using ant as task runner and we have a specific task that start the build process.
EDIT 26/01/2017
I would like to provide you other informations like the error message and one step that I've skipped before.
The error message provides a link to a Microsoft Page and reports a configuration problem.
As solved by this StackOverflow post, I've added a new DWORD registry key under
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0_Config\MSBuild\EnableOutOfProcBuild
Can the problem be that this value can't be readed when the User is'nt logged in ?
EDIT 27/01/2017
I'm going crazy with this issue.
The command devenv /? work fine when i run it locally but wont work when i run it from Jenkins with the same error as before: Microsoft Visual Studio found a configuration problem. To fix it restart as administrator or visit http://go.microsoft.com/fwlink/?LinkId=659046 for further information.
So the devenv.com cannot be executed when i'm not logged in ??
UPDATED 31/01/2017#
Here's my .bat file called from a target by ant build.xml
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat"
#set MSBUILD="C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe"
%MSBUILD% "%cd%\src\AutomatedSetupBuild.proj"
pause
Where the AutomatedSetupBuild.proj is an MSBuild script
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Target Name="Build">
<PropertyGroup>
<DevEnv>C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.com</DevEnv>
<SolutionFile>$(MSBuildProjectDirectory)\MySolution.sln</SolutionFile>
<ProjectFile>MySetupProject\MySetupProject.vdproj</ProjectFile>
<Configuration>Release</Configuration>
</PropertyGroup>
<Exec
Command=""$(DevEnv)" "$(SolutionFile)" /Rebuild "$(Configuration)" /Project "$(ProjectFile)" /ProjectConfig "$(Configuration)" /Log vs.log /useenv"
ContinueOnError="false"
IgnoreExitCode="false"
WorkingDirectory="$(MSBuildProjectDirectory)" />
</Target>
</Project>
As you can see, I'm loading the environment variable before run devenv.com but i receive the same error.
Do you use a free style job or do you use a Jenkinsfile for a pipeline project? In any case, for devenv.com to work, environment variables have to be set up.
Please go to the Windows start menu and look for something like Visual Studio XX -> Visual Studio Tools -> Developer Command Prompt for VS20XX. Press right mouse bottom and select properties. There look for target. In my case this field contains the following string:
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat""
If you use e.g. a Jenkinsfile, change the call to devnenv.com, which probably looks like
bat "devenv.com my_solution_file.sln /project my_project /build \"Release|x64\""
to
bat "call \"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat\"; devenv.com my_solution_file.sln /project my_project /build \"Release|x64\""
It is important, that the call to the VsDevCmd.bat is within the same bat command. Otherwise the environment variable settings get lost and are not seen by a second call to bat.
Open the dev command prompt type "where devenv" then call the full path with the .com version... e.g.
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.com" /Rebuild "RELEASE|Win32" "F:\project.sln"
For my part, I had to convert the Visual Studio 2015 SSRS project to SSRS Visual Studio 2017. Then I installed the 2017 SSDT for VS 2017, and use MSBUILD. Everything works well without open remote session.

Can you call an earlier version of MSBuild from 2013 from TFS build definition

Our company just migrated our project from a TFS 2012 server to 2013 TFS server as well as our build controllers (2012 servers to 2013). I know within VS2013 MSBuild is now part of the application however I have a need to also reference older build machines that build some of our SSIS and SSAS projects as part of deployment. The challenge I have is these projects use Business Intelligence for 2008R2 and I cannot migrate the solution/projects forward.
Within my analytic's solution which was authored in VS2010 I have the following build command:
<Target Name="BeforeBuild">
<!-- Build SSIS Package-->
<Exec Command=""C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" "$(MSBuildProjectDirectory)\..\AnalyticsSSAS\AnalyticsSSAS.dwproj" /Build" />
</Target>
<PropertyGroup>
<PostBuildEvent>xcopy "$(ProjectDir)..\AnalyticsSSAS\bin\*.*" /y</PostBuildEvent>
</PropertyGroup>
When I try to run a build using the 2013 definition the build fails and states that the msbiuld taks EXEC is not recognized. I can open the solution and projects individually and build them (running 2010) with no issues 2013 wants to migrate the solution to which I can't do.
Here is the actual message generated in the build log file:
"f:\blds\26\DevCI\src\Analytics.sln" (default target) (1) ->
"f:\blds\26\DevCI\src\Database\Dashboards\SSASBuild\SSASBuild.csproj" (default target) (2) ->
(BeforeBuild target) ->
f:\blds\26\DevCI\src\Database\Dashboards\SSASBuild\SSASBuild.csproj(85,5): error MSB3073: The command ""C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" "f:\blds\26\DevCI\src\Database\Dashboards\SSASBuild\..\AnalyticsSSAS\AnalyticsSSAS.dwproj" /Build" exited with code 1.
"f:\blds\26\DevCI\src\Analytics.sln" (default target) (1) ->
"f:\blds\26\DevCI\src\Database\Dashboards\SSISBuild\SSISBuild.csproj" (default target) (3) ->
f:\blds\26\DevCI\src\Database\Dashboards\SSISBuild\SSISBuild.csproj(84,5): error MSB3073: The command ""C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" "f:\blds\26\DevCI\src\Database\Dashboards\SSISBuild\..\AnalyticsSSIS\AnalyticsSSIS.dtproj" /Build" exited with code 1.
I suspect from what I have read that MSBuild in VS2013 will not allow for a lower version of MSBuild v9.0 to be referenced without migrating the project to a newer version.
Has anyone seen this before and is there any workaround for this type of build?
-cheers
I think there are many solution, but the basic idea is to force using the old MSBuild version.
Custom Build Template (old style)
Add an MSBuild activity and set the ToolPath Property to the old version. You must expose a list of solutions to build as Template arguments.
Script (new style)
Write a post-build (or pre-build) script that invokes the proper MSBuild version with the path to the solution.

Resources