0

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 Answer 1

3

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Works fine, however I used "ProjectReference" instead of "ProjectToBuild", because that element is in the schema, seems like both options work though.
Any identifier, which is suitable for xml tag is perfectly valid here, does not matter if it's not in schema. It's in schema just for proprietary csproj files. msdn.microsoft.com/en-us/library/646dk05y.aspx, i would not recommend reusing this just because it's in schema for intellisence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.