Skip to content

Instantly share code, notes, and snippets.

@jstangroome
Created February 3, 2012 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jstangroome/1727206 to your computer and use it in GitHub Desktop.
Save jstangroome/1727206 to your computer and use it in GitHub Desktop.
An auto-imported solution targets file to stop Team Build from overriding the OutDir property. Just put this file in your solution folder and rename 'TheSolution' to match the solution filename.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask Condition="'$(OutDir)' != ''"
TaskName="MSBuild"
TaskFactory="CodeTaskFactory"
AssemblyName="Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<ParameterGroup>
<Projects ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
<BuildInParallel ParameterType="System.Boolean" />
<Properties ParameterType="System.String[]" />
<SkipNonexistentProjects ParameterType="System.String" />
<TargetOutputs ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" />
<Targets ParameterType="System.String[]" />
</ParameterGroup>
<Task>
<Reference Include="Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var newProperties = new System.Collections.Generic.List<string>(Properties);
newProperties.Add(@"PreferredOutDir=$(OutDir)");
var childTask = new Microsoft.Build.Tasks.MSBuild();
childTask.BuildEngine = BuildEngine;
childTask.Projects = Projects;
childTask.BuildInParallel = BuildInParallel;
childTask.Properties = newProperties.ToArray();
childTask.SkipNonexistentProjects = SkipNonexistentProjects;
childTask.Targets = Targets;
childTask.RemoveProperties = "OutDir"; // Magic happens here!
var result = childTask.Execute();
TargetOutputs = childTask.TargetOutputs;
return result;
]]>
</Code>
</Task>
</UsingTask>
</Project>
@mfuxi
Copy link

mfuxi commented Apr 27, 2015

For most of my projects this solution works great, but I got one project which has build errors because of this addition to my solution directory.

The Error are like these for several projects: *****.csproj.metaproj: The project file could not be loaded. Could not find file ****.csproj.metaproj'.

Do u have any idea?

10x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment