Create with msbuild and dynamically set project links

I have several projects that reference SQL Server assemblies. In SQL Server 2005 and SQL Server 2008, I currently support 2 project files that point to the same source files, and the only difference is the references to SQL Server assemblies.

Is there a way that I can only support one project and dynamically specify links in my build script?

+7
reference msbuild
source share
2 answers

Finding a solution to the same problem that you encountered, I came to the proposed solution about the condition in ItemGroup. But this had a side effect, because in the links in Visual Studio I could see both links that also affected ReSharper.

Finally, I use the Select When command, and I no longer have problems with ReSharper and Visual Studio showing two links.

<Choose> <When Condition=" '$(Configuration)' == 'client1DeployClickOnce' "> <ItemGroup> <ProjectReferenceInclude="..\client1\app.Controls\app.Controls.csproj"> <Project>{A7714633-66D7-4099-A255-5A911DB7BED8}</Project> <Name>app.Controls %28Sources\client1\app.Controls%29</Name> </ProjectReference> </ItemGroup> </When> <Otherwise> <ItemGroup> <ProjectReference Include="..\app.Controls\app.Controls.csproj"> <Project>{2E6D4065-E042-44B9-A569-FA1C36F1BDCE}</Project> <Name>app.Controls %28Sources\app.Controls%29</Name> </ProjectReference> </ItemGroup> </Otherwise> </Choose> 

You can read more about this in your blog post: ProjectReference with Condition in the MSBuild project file

+15
source share

Each MSBuild item (almost every one) can have a Condition associated with it. I would suggest that you edit the project file (which is the MSBuild file itself) and place all the SQL server links in an ItemGroup on which there is a condition, for example:

  <ItemGroup Condition="'$(SqlServerTargetEdition)'=='2005'"> <!-- SQL Server 2005 References here --> <Reference Include="..."/> </ItemGroup> 

And another ItemGroup for Sql 2008 server:

  <ItemGroup Condition="'$(SqlServerTargetEdition)'=='2008'"> <!-- SQL Server 2008 References here --> <Reference Include="..."/> </ItemGroup> 

You must specify a default value for the SqlServerTargetEdition property before declaring these elements. Then, on the command line, you can override this value with the / p switch when you call msbuild.exe .

Said Ibrahim Hashimi

My book: Inside Microsoft Build Engine: Using MSBuild and Team Foundation Build

+5
source share

All Articles