Created
May 13, 2013 23:42
-
-
Save vadimi/5572483 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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