Created
May 13, 2013 23:37
-
-
Save vadimi/5572446 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
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<PropertyGroup> | |
<ScriptsDir>Layouts\MyCoolProject\Scripts</ScriptsDir> | |
<ManifestPath>pkg\Release\MyCoolProject</ManifestPath> | |
</PropertyGroup> | |
<ItemGroup> | |
<ExcludedFiles Include=" | |
$(ScriptsDir)\jquery-1.9.1.js; | |
$(ScriptsDir)\backbone.js; | |
$(ScriptsDir)\backbone-sharepoint.extensions.js; | |
$(ScriptsDir)\backbone-sharepoint.odata.js; | |
$(ScriptsDir)\backbone-sharepoint.soap.js; | |
$(ScriptsDir)\backbone-super.js; | |
$(ScriptsDir)\underscore.js" | |
/> | |
</ItemGroup> | |
<UsingTask TaskName="FindInEnumeration" TaskFactory="CodeTaskFactory" | |
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> | |
<ParameterGroup> | |
<SourceFiles ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> | |
<Files ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> | |
<Result ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="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 filesToFind = Files.Select(item => item.GetMetadata("FullPath")).ToArray(); | |
Result = SourceFiles | |
.Where(file => filesToFind.Contains(file.ItemSpec)) | |
.ToArray(); | |
return true; | |
} | |
catch (Exception ex) | |
{ | |
Log.LogErrorFromException(ex); | |
return false; | |
} | |
]]> | |
</Code> | |
</Task> | |
</UsingTask> | |
<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> | |
<!-- It's possible to override some targets defined in | |
c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\SharePointTools\Microsoft.VisualStudio.SharePoint.targets | |
that allow to insert custom actions during publishing of SharePoint project | |
--> | |
<Target Name="BeforeLayout" Condition="'$(Configuration)'=='Release'"> | |
<FindInEnumeration Files="@(ExcludedFiles)" SourceFiles="@(EnumeratedFiles)"> | |
<Output ItemName="Result" TaskParameter="Result" /> | |
</FindInEnumeration> | |
<ItemGroup> | |
<!-- EnumeratedFiles defined in Microsoft.VisualStudio.SharePoint.targets | |
and contains ALL project files, so we need to remove excluded files | |
from this enumeration. After that they will NOT be copied over to destination WSP | |
--> | |
<EnumeratedFiles Remove="@(Result)"/> | |
</ItemGroup> | |
</Target> | |
<Target Name="AfterLayout" Condition="'$(Configuration)'=='Release'"> | |
<!-- We have to exclude files from manifest.xml separately --> | |
<ExcludeFromManifest Files="@(ExcludedFiles)" ManifestPath="$(ManifestPath)" /> | |
</Target> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment