开发者

Working directory issue when importing msbuild file in another msbuild file

开发者 https://www.devze.com 2023-04-09 04:06 出处:网络
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 开发者_如何学JAVAis to put configuration speci

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 开发者_如何学JAVAis 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.


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号