Skip to content

Instantly share code, notes, and snippets.

@vadimi
Created May 13, 2013 23:42
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 vadimi/5572483 to your computer and use it in GitHub Desktop.
Save vadimi/5572483 to your computer and use it in GitHub Desktop.
<UsingTask TaskName="ExcludeFromManifest" TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<ManifestPath ParameterType="System.String" Required="true" />
<Files ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
<Using Namespace="System" />
<Using Namespace="System.Reflection" />
<Using Namespace="System.IO" />
<Using Namespace="System.Linq" />
<Using Namespace="System.Xml.Linq" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try
{
var excludedFiles = Files.Select(item => item.ItemSpec).ToArray();
var manifestPath = ManifestPath.TrimEnd(new[] { '\\' }) + @"\manifest.xml";
var manifestXml = File.ReadAllText(manifestPath);
var manifest = XElement.Parse(manifestXml);
var excludedElements =
manifest.Descendants().Where(element => element.Name.LocalName == "TemplateFile")
.Where(element => excludedFiles.Contains((string) element.Attribute("Location")));
excludedElements.Remove();
manifest.Save(manifestPath);
return true;
}
catch (Exception ex)
{
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment