Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Custom MSBuild steps for a SharePoint .csproj file - to perform find/replace of SspId value for Managed Metadata fields in Office 365.
<Import Project="$(VSToolsPath)\SharePointTools\Microsoft.VisualStudio.SharePoint.targets" Condition="'$(VSToolsPath)' != ''" />
<!-- COB 15/08/2013: This next target does the work of replacing the SspId.. -->
<Target Name="AfterLayout" Condition="$(Configuration) != 'Debug' AND $(Configuration) != 'Release'">
<!-- Set some variables.. -->
<PropertyGroup>
<ReplacementsFile>_Replacements\SspId_Replacements.xml</ReplacementsFile>
</PropertyGroup>
<!-- Fetch the appropriate value from the environments.xml file.. -->
<Message Text="Going to look for Environment node with Name ='$(Configuration)' in file $(ReplacementsFile).." Importance="high" />
<XmlPeek XmlInputPath="$(ReplacementsFile)" Query="Replacements/Environment[@Name='$(Configuration)']/SspId/text()">
<Output TaskParameter="Result" ItemName="FetchedSspIdValue" />
</XmlPeek>
<Message Text="Fetched SspId value of @(FetchedSspIdValue) from $(ReplacementsFile) file" Importance="high" />
<!-- Now make replacements.. -->
<ItemGroup>
<FilesForSspIdReplacement Include="$(LayoutPath)**\*.xml">
</FilesForSspIdReplacement>
</ItemGroup>
<!-- In elements.xml files containing field definitions.. -->
<XmlPoke XmlInputPath="%(FilesForSspIdReplacement.Identity)" Namespaces="&lt;Namespace Prefix='x' Uri='http://schemas.microsoft.com/sharepoint/'/&gt;&lt;Namespace Prefix='q1' Uri='http://www.w3.org/2001/XMLSchema'/&gt;&lt;Namespace Prefix='p4' Uri='http://www.w3.org/2001/XMLSchema-instance'/&gt;" Query="x:Elements/x:Field/x:Customization/x:ArrayOfProperty/x:Property[x:Name='SspId']/x:Value" Value="@(FetchedSspIdValue)" />
<!-- ..and in list schema.xml files.. -->
<XmlPoke XmlInputPath="%(FilesForSspIdReplacement.Identity)" Namespaces="&lt;Namespace Prefix='x' Uri='http://schemas.microsoft.com/sharepoint/'/&gt;&lt;Namespace Prefix='q1' Uri='http://www.w3.org/2001/XMLSchema'/&gt;&lt;Namespace Prefix='p4' Uri='http://www.w3.org/2001/XMLSchema-instance'/&gt;&lt;Namespace Prefix='ows' Uri='Microsoft SharePoint'/&gt;" Query="x:List/x:MetaData/x:Fields/x:Field/x:Customization/x:ArrayOfProperty/x:Property[x:Name='SspId']/x:Value" Value="@(FetchedSspIdValue)" />
</Target>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment