Created
March 15, 2016 19:17
-
-
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
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
<?xml version="1.0" encoding="utf-8"?> | |
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<PropertyGroup> | |
<XmlNamespace><Namespace Prefix='vs' Uri='http://schemas.microsoft.com/developer/vstemplate/2005'/></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)[^<]+</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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Depends on Clarius.VisualStudio nuget