Add a version to the Razor about dialog entry

This commit is contained in:
Ryan Nowak 2018-03-22 14:54:20 -07:00
parent c874f84c3d
commit 0a450d2f53
3 changed files with 103 additions and 4 deletions

View File

@ -0,0 +1,64 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Reflection;
using Microsoft.VisualStudio.Shell;
namespace Microsoft.VisualStudio.RazorExtension
{
public class AboutDialogInfoAttribute : RegistrationAttribute
{
private readonly string _detailsId;
private readonly string _name;
private readonly string _nameId;
private readonly string _packageGuid;
// nameId and detailsId are resource IDs, they should start with #
public AboutDialogInfoAttribute(string packageGuid, string name, string nameId, string detailsId)
{
_packageGuid = packageGuid;
_name = name;
_nameId = nameId;
_detailsId = detailsId;
}
// This is a resource ID it should start with #
public string IconResourceID { get; set; }
private string GetKeyName()
{
return "InstalledProducts\\" + _name;
}
public override void Register(RegistrationContext context)
{
var attribute = typeof(AboutDialogInfoAttribute).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
var version = attribute?.InformationalVersion;
using (var key = context.CreateKey(GetKeyName()))
{
key.SetValue(null, _nameId);
key.SetValue("Package", Guid.Parse(_packageGuid).ToString("B"));
key.SetValue("ProductDetails", _detailsId);
key.SetValue("UseInterface", false);
key.SetValue("UseVSProductID", false);
if (version != null)
{
key.SetValue("PID", version);
}
if (IconResourceID != null)
{
key.SetValue("LogoID", IconResourceID);
}
}
}
public override void Unregister(RegistrationContext context)
{
context.RemoveKey(GetKeyName());
}
}
}

View File

@ -24,6 +24,7 @@
<ImportDirectoryBuildProps>false</ImportDirectoryBuildProps>
<ImportDirectoryBuildTargets>false</ImportDirectoryBuildTargets>
</PropertyGroup>
<Import Project="..\..\version.props" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -65,6 +66,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="AboutDialogInfoAttribute.cs" />
<Compile Include="DocumentInfo\RazorDocumentInfoViewModel.cs" />
<Compile Include="DocumentInfo\RazorDocumentInfoWindow.cs" />
<Compile Include="DocumentInfo\RazorDocumentInfoWindowCommand.cs" />
@ -265,11 +267,9 @@
<SuppressFromVsix Include="System.Xml.XPath.dll" />
<SuppressFromVsix Include="System.Xml.XPath.XDocument.dll" />
</ItemGroup>
<Target Name="CopySymbolsToOutput" AfterTargets="Build" Condition="'$(SymbolsPublishDir)' != ''">
<Copy SourceFiles="$(OutDir)$(AssemblyName).pdb" DestinationFolder="$(SymbolsPublishDir)" />
</Target>
<!--
Begin workaround for https://github.com/dotnet/sdk/issues/433
@ -298,4 +298,39 @@
<Target Name="GetBuildVersion" Outputs="$(VsixVersion)" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="Exists('$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets')" />
<!-- Must be defined after the CSharp.targets -->
<PropertyGroup>
<_GeneratedVSIXAssemblyInfoInputsCacheFile>$(IntermediateOutputPath)$(MSBuildProjectName).VSIXAssemblyInfo.cache.txt</_GeneratedVSIXAssemblyInfoInputsCacheFile>
<_GeneratedVSIXAssemblyInfoFile>$(IntermediateOutputPath)$(MSBuildProjectName).VSIXAssemblyInfo.cs</_GeneratedVSIXAssemblyInfoFile>
</PropertyGroup>
<!--
We need to generate the assembly attributes for our assembly using the version from the build, so
we can flow it to the about dialog.
-->
<ItemGroup>
<_VSIXAssemblyAttribute Include="System.Reflection.AssemblyInformationalVersionAttribute">
<_Parameter1>$(VsixVersion)</_Parameter1>
</_VSIXAssemblyAttribute>
</ItemGroup>
<Target Name="_GenerateVSIXAssemblyAttributesHash" DependsOnTargets="PrepareForBuild" Condition="'@(_VSIXAssemblyAttribute)' != ''">
<!-- We only use up to _Parameter1 for most attributes, but other targets may add additional assembly attributes with multiple parameters. -->
<Hash ItemsToHash="@(_VSIXAssemblyAttribute->'%(Identity)%(_Parameter1)%(_Parameter2)%(_Parameter3)%(_Parameter4)%(_Parameter5)%(_Parameter6)%(_Parameter7)%(_Parameter8)')">
<Output TaskParameter="HashResult" PropertyName="_VSIXAssemblyAttributesHash" />
</Hash>
<WriteLinesToFile Lines="$(_VSIXAssemblyAttributesHash)" File="$(_GeneratedVSIXAssemblyInfoInputsCacheFile)" Overwrite="True" WriteOnlyWhenDifferent="True" />
<ItemGroup>
<FileWrites Include="$(_GeneratedVSIXAssemblyInfoInputsCacheFile)" />
</ItemGroup>
</Target>
<Target Name="_GenerateVSIXAssemblyAttributes" DependsOnTargets="_GenerateVSIXAssemblyAttributesHash" Inputs="$(_GeneratedVSIXAssemblyInfoInputsCacheFile)" Outputs="$(_GeneratedVSIXAssemblyInfoFile)" BeforeTargets="CoreCompile">
<ItemGroup>
<Compile Include="$(_GeneratedVSIXAssemblyInfoFile)">
<Visible>false</Visible>
</Compile>
</ItemGroup>
<WriteCodeFragment AssemblyAttributes="@(_VSIXAssemblyAttribute)" Language="C#" OutputFile="$(_GeneratedVSIXAssemblyInfoFile)" />
<ItemGroup>
<FileWrites Include="$(_GeneratedVSIXAssemblyInfoFile)" />
</ItemGroup>
</Target>
</Project>

View File

@ -9,8 +9,8 @@ using Microsoft.VisualStudio.Shell.Interop;
namespace Microsoft.VisualStudio.RazorExtension
{
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[Guid(RazorPackage.PackageGuidString)]
[AboutDialogInfo(PackageGuidString, "ASP.NET Core Razor Language Services", "#110", "#112", IconResourceID = "#400")]
[Guid(PackageGuidString)]
[ProvideMenuResource("Menus.ctmenu", 1)]
#if RAZOR_EXTENSION_DEVELOPER_MODE
[ProvideToolWindow(typeof(Microsoft.VisualStudio.RazorExtension.RazorInfo.RazorInfoToolWindow))]