0
votes

I am trying to specify some additional targets/tasks to an msbuild file by extending an existing msbuild file (a web applicartion .csproj file). The idea is to put configuration specific tasks in this "extended ms build file" and use this file in our build server (TeamCity). The way I tried to solve it at first was to add a folder "msbuildscripts" to my web project and put the extended ms build file there:

<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
  <Import Project="../My.Web.csproj" />
  ...more stuff...
</Project>

and then build this file using something like:

c:\myweb\msbuild.exe msbuildscripts/extended.msbuild.file.xml

Now, this wont work because when importing the original ms build file, that csproj file will be "executed" in the "wrong" folder (msbuildscripts), and the csproj-build-file wont find any of its referenced folders/items.

Is there any way to tell msbuild.exe to use a specific working directory? I know it is possible to solve this problem using an execute task, but that doesnt seem like a good solution.

1

1 Answers

3
votes

Use MSBuild task like this:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="MyBuild">

<ItemGroup>
 <ProjectToBuild Include="../My.Web.csproj" />
</ItemGroup>

<Target Name="MyBuild">
 <MSBuild Targets="Build" Projects="@(ProjectToBuild)"></MSBuild>
</Target>
</Project>