Skip to content

Instantly share code, notes, and snippets.

@kzu
Created March 15, 2016 19:17
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 kzu/b23c4d2d709599975f5f to your computer and use it in GitHub Desktop.
Save kzu/b23c4d2d709599975f5f to your computer and use it in GitHub Desktop.
Fixup vstemplate wizard if they have a version in the assembly name, to match GitInfo.Vsix's VsixVersion
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<XmlNamespace>&lt;Namespace Prefix='vs' Uri='http://schemas.microsoft.com/developer/vstemplate/2005'/&gt;</XmlNamespace>
</PropertyGroup>
<Target Name="ExtractPublicKey"
Inputs="$(AssemblyOriginatorKeyFile)"
Outputs="$(IntermediateOutputPath)key.pub">
<Exec Command='"$(TargetFrameworkSDKToolsDirectory)sn.exe" -p "$(AssemblyOriginatorKeyFile)" "$(IntermediateOutputPath)key.pub"' />
<ItemGroup>
<FileWrites Include="$(IntermediateOutputPath)key.pub" />
</ItemGroup>
</Target>
<Target Name="ExtractPublicKeyToken"
Inputs="$(IntermediateOutputPath)key.pub"
Outputs="$(IntermediateOutputPath)key.txt">
<Exec Command='"$(TargetFrameworkSDKToolsDirectory)sn.exe" -t "$(IntermediateOutputPath)key.pub"'
ConsoleToMSBuild='true'>
<Output TaskParameter="ConsoleOutput" PropertyName="_SnOutput"/>
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<Error Condition="'$(MSBuildLastExitCode)' != '0'"
Text="$(_SnOutput)" />
<PropertyGroup Condition=" '$(_SnOutput)' != '' ">
<PublicKeyToken>$(_SnOutput.Substring($(_SnOutput.LastIndexOf(' '))).Trim())</PublicKeyToken>
</PropertyGroup>
<WriteLinesToFile File="$(IntermediateOutputPath)key.txt"
Lines="$(PublicKeyToken)"
Condition=" '$(PublicKeyToken)' != '' "
Overwrite="true" />
<ItemGroup>
<FileWrites Include="$(IntermediateOutputPath)key.txt" />
</ItemGroup>
</Target>
<Target Name="ReadPublicKeyToken" Condition=" '$(PublicKeyToken)' == '' ">
<ReadLinesFromFile File="$(IntermediateOutputPath)key.txt">
<Output TaskParameter="Lines" PropertyName="PublicKeyToken" />
</ReadLinesFromFile>
</Target>
<PropertyGroup>
<FixupTemplateWizardsDependsOn>
ExtractPublicKey;
ExtractPublicKeyToken;
ReadPublicKeyToken;
GitInfo;
VsixInfo
</FixupTemplateWizardsDependsOn>
</PropertyGroup>
<Target Name="FixupTemplateWizards"
Inputs="$(MSBuildAllProjects);
@(_GitInputs);
@(SmartTemplateWithTargetPath)"
Outputs="@(SmartTemplateWithTargetPath->'$(SmartTemplateIntermediateOutputPath)%(TargetPath)')"
DependsOnTargets="$(FixupTemplateWizardsDependsOn)"
BeforeTargets="ZipSmartTemplateContent;GetVsixSourceItems"
Condition="'@(SmartTemplateWithTargetPath)' != ''">
<PropertyGroup>
<TemplateContent>$([System.IO.File]::ReadAllText('$(SmartTemplateIntermediateOutputPath)%(SmartTemplateWithTargetPath.TargetPath)'))</TemplateContent>
<AssemblyNameRegex>$(AssemblyName)[^&lt;]+</AssemblyNameRegex>
<AssemblyNameReplacement></AssemblyNameReplacement>
<TemplateContent>$([System.Text.RegularExpressions.Regex]::Replace('$(TemplateContent)', '$(AssemblyNameRegex)', '$(AssemblyName), Version=$(VsixVersion), Culture=neutral, PublicKeyToken=$(PublicKeyToken)'))</TemplateContent>
</PropertyGroup>
<WriteLinesToFile File="$(SmartTemplateIntermediateOutputPath)%(SmartTemplateWithTargetPath.TargetPath)"
Lines="$(TemplateContent)"
Overwrite="true" />
</Target>
</Project>
@kzu
Copy link
Author

kzu commented Mar 15, 2016

Depends on Clarius.VisualStudio nuget

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