How do I get Visual Studio 2010 to pass a variable to MSBuild?

I created my own msbuild deploy.targets file, which allows me to publish the resulting binaries to the directory that I specify on the command line. This means that if I run

$> msbuild / p: DestServer = \ myserver \ final-dest

then my project will be compiled, and the resulting * .dll will be copied to an intermediate instance - in this case, the final-dest directory on myserver. I want this functionality because when I do compilation forever, I need a copy of * .dll in this directory, but I also want them to be local.

Here is my problem - I would really like not to release this from the command line. When I select the assembly assembly configuration (Project | Properties | Build), I would like to specify the / p: DestServer = \ myserver \ final-dest option as an argument that msbuild will use since it does its normal assembly.

Where can I point this out?

In project properties | Build Events, I could indicate pre-assembly or post-assembly events, but is this not “part of the assembly”?

Ideally, if someone could give me a menu sequence in Visual Studio 2010, I would appreciate it.

+2
source share
2 answers

If you do not want to edit project files, there is another solution.

Each * .csproj file contains the following: <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> .

On my computer and .Net 4.0, this file is located in "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets"

Add PropertyGroup inside Project :

 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> ... <PropertyGroup> <DestServer>\myserver\final-dest</DestServer> </PropertyGroup> ... <!-- a lot of stuff --> ... </Project> 

All your assemblies will now (either from MSBuild and Visual Studio) use this property, so you do not need to modify .csproj or pass arguments from the command line

Update

It was a quick and dirty way, since it would cover all the projects created on this PC. Only do this if there are many projects, and you do not have the right to change them.

Usually you just add a new PropertyGroup inside the same project.

If there are many projects where you need this variable, you can create and import your extension targets below the default targets:

App1.csproj

 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> ... <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="..\myCustom.targets" /> ... </Project> 

and

myCustom.targets

 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <DestServer>\myserver\final-dest</DestServer> </PropertyGroup> </Project> 
+3
source

I don’t know how to set this via the VisualStudio GUI (there might be nothing there), but you just have to edit the .csproj / .vcproj file to add this property to the appropriate configurations:

 <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion>9.0.30729</ProductVersion> ... ...etc ... </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DestServer>\myserver\final-dest</DestServer> <!-- <<<<< HERE <<<<< --> ... 

Visual Studio will retain this even if you edit other properties using the graphical interface (at least it has a tendency ...)

+1
source

All Articles