Remove T4 custom tool

- use same generator as most other projects in aspnet repos
  - were not using named arguments to resource methods anyhow
- update resources to use regular (numbered) format parameters
- adjust to new `Resources` namespace; no need for separate `using`
- use `Format...(...)` methods as necessary
This commit is contained in:
Doug Bunting 2018-09-06 11:39:50 -07:00
parent e19c036f11
commit 6ffcf3571e
No known key found for this signature in database
GPG Key ID: 888B4EB7822B32E9
18 changed files with 590 additions and 557 deletions

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.Extensions.ApiDescription.Client.Properties;
namespace Microsoft.Extensions.ApiDescription.Client.Commands
{

View File

@ -9,7 +9,6 @@ using System.Reflection;
using System.Runtime.Loader;
#endif
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.Extensions.ApiDescription.Client.Properties;
namespace Microsoft.Extensions.ApiDescription.Client.Commands
{
@ -32,10 +31,10 @@ namespace Microsoft.Extensions.ApiDescription.Client.Commands
_documentName = command.Option(
"--documentName <Name>",
Resources.DocumentDescription(FallbackDocumentName));
_method = command.Option("--method <Name>", Resources.MethodDescription(FallbackMethod));
Resources.FormatDocumentDescription(FallbackDocumentName));
_method = command.Option("--method <Name>", Resources.FormatMethodDescription(FallbackMethod));
_output = command.Option("--output <Path>", Resources.OutputDescription);
_service = command.Option("--service <QualifiedName>", Resources.ServiceDescription(FallbackService));
_service = command.Option("--service <QualifiedName>", Resources.FormatServiceDescription(FallbackService));
_uri = command.Option("--uri <URI>", Resources.UriDescription);
}
@ -45,17 +44,17 @@ namespace Microsoft.Extensions.ApiDescription.Client.Commands
if (!_output.HasValue())
{
throw new CommandException(Resources.MissingOption(_output.LongName));
throw new CommandException(Resources.FormatMissingOption(_output.LongName));
}
if (_method.HasValue() && !_service.HasValue())
{
throw new CommandException(Resources.MissingOption(_service.LongName));
throw new CommandException(Resources.FormatMissingOption(_service.LongName));
}
if (_service.HasValue() && !_method.HasValue())
{
throw new CommandException(Resources.MissingOption(_method.LongName));
throw new CommandException(Resources.FormatMissingOption(_method.LongName));
}
}

View File

@ -6,7 +6,6 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.ApiDescription.Client.Properties;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -21,7 +20,7 @@ namespace Microsoft.Extensions.ApiDescription.Client.Commands
var entryPointType = assembly.EntryPoint?.DeclaringType;
if (entryPointType == null)
{
Reporter.WriteError(Resources.MissingEntryPoint(context.AssemblyPath));
Reporter.WriteError(Resources.FormatMissingEntryPoint(context.AssemblyPath));
return 2;
}
@ -68,9 +67,9 @@ namespace Microsoft.Extensions.ApiDescription.Client.Commands
GetDocumentCommand.FallbackService :
context.Service;
Reporter.WriteInformation(Resources.UsingDocument(documentName));
Reporter.WriteInformation(Resources.UsingMethod(methodName));
Reporter.WriteInformation(Resources.UsingService(serviceName));
Reporter.WriteInformation(Resources.FormatUsingDocument(documentName));
Reporter.WriteInformation(Resources.FormatUsingMethod(methodName));
Reporter.WriteInformation(Resources.FormatUsingService(serviceName));
try
{
@ -93,7 +92,7 @@ namespace Microsoft.Extensions.ApiDescription.Client.Commands
if (!success)
{
var message = Resources.MethodInvocationFailed(methodName, serviceName, documentName);
var message = Resources.FormatMethodInvocationFailed(methodName, serviceName, documentName);
if (string.IsNullOrEmpty(context.Uri) && !File.Exists(context.Output))
{
Reporter.WriteError(message);
@ -126,7 +125,7 @@ namespace Microsoft.Extensions.ApiDescription.Client.Commands
{
Debug.Assert(!string.IsNullOrEmpty(context.Uri));
Reporter.WriteInformation(Resources.UsingUri(context.Uri));
Reporter.WriteInformation(Resources.FormatUsingUri(context.Uri));
var httpClient = server.CreateClient();
await DownloadFileCore.DownloadAsync(

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.Extensions.ApiDescription.Client.Properties;
namespace Microsoft.Extensions.ApiDescription.Client.Commands
{
@ -26,12 +25,12 @@ namespace Microsoft.Extensions.ApiDescription.Client.Commands
if (!AssemblyPath.HasValue())
{
throw new CommandException(Resources.MissingOption(AssemblyPath.LongName));
throw new CommandException(Resources.FormatMissingOption(AssemblyPath.LongName));
}
if (!ToolsDirectory.HasValue())
{
throw new CommandException(Resources.MissingOption(ToolsDirectory.LongName));
throw new CommandException(Resources.FormatMissingOption(ToolsDirectory.LongName));
}
}
}

View File

@ -17,23 +17,4 @@
<Compile Include="../Microsoft.Extensions.ApiDescription.Client/ILogWrapper.cs" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(MicrosoftAspNetCoreTestHost20PackageVersion)" />
</ItemGroup>
<ItemGroup>
<None Update="Properties/Resources.Designer.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties/Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.Designer.tt</DependentUpon>
</Compile>
</ItemGroup>
</Project>

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.Extensions.ApiDescription.Client.Properties;
namespace Microsoft.Extensions.ApiDescription.Client
{

View File

@ -1,207 +1,366 @@
// <auto-generated />
using System;
using System.Reflection;
using System.Resources;
using JetBrains.Annotations;
namespace Microsoft.Extensions.ApiDescription.Client.Properties
namespace Microsoft.Extensions.ApiDescription.Client
{
/// <summary>
/// This API supports the GetDocument infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
using System.Globalization;
using System.Reflection;
using System.Resources;
internal static class Resources
{
private static readonly ResourceManager _resourceManager
= new ResourceManager("Microsoft.Extensions.ApiDescription.Client.Properties.Resources", typeof(Resources).GetTypeInfo().Assembly);
= new ResourceManager("Microsoft.Extensions.ApiDescription.Client.Resources", typeof(Resources).GetTypeInfo().Assembly);
/// <summary>
/// The assembly to use.
/// The assembly to use.
/// </summary>
public static string AssemblyDescription
internal static string AssemblyDescription
{
get => GetString("AssemblyDescription");
}
/// <summary>
/// The assembly to use.
/// </summary>
internal static string FormatAssemblyDescription()
=> GetString("AssemblyDescription");
/// <summary>
/// Show JSON output.
/// Show JSON output.
/// </summary>
public static string JsonDescription
internal static string JsonDescription
{
get => GetString("JsonDescription");
}
/// <summary>
/// Show JSON output.
/// </summary>
internal static string FormatJsonDescription()
=> GetString("JsonDescription");
/// <summary>
/// Missing required option '--{option}'.
/// Missing required option '--{0}'.
/// </summary>
public static string MissingOption([CanBeNull] object option)
=> string.Format(
GetString("MissingOption", nameof(option)),
option);
internal static string MissingOption
{
get => GetString("MissingOption");
}
/// <summary>
/// Do not colorize output.
/// Missing required option '--{0}'.
/// </summary>
public static string NoColorDescription
internal static string FormatMissingOption(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("MissingOption"), p0);
/// <summary>
/// Do not colorize output.
/// </summary>
internal static string NoColorDescription
{
get => GetString("NoColorDescription");
}
/// <summary>
/// Do not colorize output.
/// </summary>
internal static string FormatNoColorDescription()
=> GetString("NoColorDescription");
/// <summary>
/// The file to write the result to.
/// The file to write the result to.
/// </summary>
public static string OutputDescription
internal static string OutputDescription
{
get => GetString("OutputDescription");
}
/// <summary>
/// The file to write the result to.
/// </summary>
internal static string FormatOutputDescription()
=> GetString("OutputDescription");
/// <summary>
/// Prefix console output with logging level.
/// Prefix console output with logging level.
/// </summary>
public static string PrefixDescription
internal static string PrefixDescription
{
get => GetString("PrefixDescription");
}
/// <summary>
/// Prefix console output with logging level.
/// </summary>
internal static string FormatPrefixDescription()
=> GetString("PrefixDescription");
/// <summary>
/// Using application base '{appBase}'.
/// Using application base '{0}'.
/// </summary>
public static string UsingApplicationBase([CanBeNull] object appBase)
=> string.Format(
GetString("UsingApplicationBase", nameof(appBase)),
appBase);
internal static string UsingApplicationBase
{
get => GetString("UsingApplicationBase");
}
/// <summary>
/// Using assembly '{assembly}'.
/// Using application base '{0}'.
/// </summary>
public static string UsingAssembly([CanBeNull] object assembly)
=> string.Format(
GetString("UsingAssembly", nameof(assembly)),
assembly);
internal static string FormatUsingApplicationBase(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("UsingApplicationBase"), p0);
/// <summary>
/// Using configuration file '{config}'.
/// Using assembly '{0}'.
/// </summary>
public static string UsingConfigurationFile([CanBeNull] object config)
=> string.Format(
GetString("UsingConfigurationFile", nameof(config)),
config);
internal static string UsingAssembly
{
get => GetString("UsingAssembly");
}
/// <summary>
/// Show verbose output.
/// Using assembly '{0}'.
/// </summary>
public static string VerboseDescription
internal static string FormatUsingAssembly(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("UsingAssembly"), p0);
/// <summary>
/// Using configuration file '{0}'.
/// </summary>
internal static string UsingConfigurationFile
{
get => GetString("UsingConfigurationFile");
}
/// <summary>
/// Using configuration file '{0}'.
/// </summary>
internal static string FormatUsingConfigurationFile(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("UsingConfigurationFile"), p0);
/// <summary>
/// Show verbose output.
/// </summary>
internal static string VerboseDescription
{
get => GetString("VerboseDescription");
}
/// <summary>
/// Show verbose output.
/// </summary>
internal static string FormatVerboseDescription()
=> GetString("VerboseDescription");
/// <summary>
/// Writing '{file}'...
/// Writing '{0}'...
/// </summary>
public static string WritingFile([CanBeNull] object file)
=> string.Format(
GetString("WritingFile", nameof(file)),
file);
internal static string WritingFile
{
get => GetString("WritingFile");
}
/// <summary>
/// Using working directory '{workingDirectory}'.
/// Writing '{0}'...
/// </summary>
public static string UsingWorkingDirectory([CanBeNull] object workingDirectory)
=> string.Format(
GetString("UsingWorkingDirectory", nameof(workingDirectory)),
workingDirectory);
internal static string FormatWritingFile(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("WritingFile"), p0);
/// <summary>
/// Location from which inside man was copied (in the .NET Framework case) or loaded.
/// Using working directory '{0}'.
/// </summary>
public static string ToolsDirectoryDescription
internal static string UsingWorkingDirectory
{
get => GetString("UsingWorkingDirectory");
}
/// <summary>
/// Using working directory '{0}'.
/// </summary>
internal static string FormatUsingWorkingDirectory(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("UsingWorkingDirectory"), p0);
/// <summary>
/// Location from which inside man was copied (in the .NET Framework case) or loaded.
/// </summary>
internal static string ToolsDirectoryDescription
{
get => GetString("ToolsDirectoryDescription");
}
/// <summary>
/// Location from which inside man was copied (in the .NET Framework case) or loaded.
/// </summary>
internal static string FormatToolsDirectoryDescription()
=> GetString("ToolsDirectoryDescription");
/// <summary>
/// The URI to download the document from.
/// The URI to download the document from.
/// </summary>
public static string UriDescription
internal static string UriDescription
{
get => GetString("UriDescription");
}
/// <summary>
/// The URI to download the document from.
/// </summary>
internal static string FormatUriDescription()
=> GetString("UriDescription");
/// <summary>
/// The name of the method to invoke on the '--service' instance. Default value '{defaultMethod}'.
/// The name of the method to invoke on the '--service' instance. Default value '{0}'.
/// </summary>
public static string MethodDescription([CanBeNull] object defaultMethod)
=> string.Format(
GetString("MethodDescription", nameof(defaultMethod)),
defaultMethod);
internal static string MethodDescription
{
get => GetString("MethodDescription");
}
/// <summary>
/// The qualified name of the service type to retrieve from dependency injection. Default value '{defaultService}'.
/// The name of the method to invoke on the '--service' instance. Default value '{0}'.
/// </summary>
public static string ServiceDescription([CanBeNull] object defaultService)
=> string.Format(
GetString("ServiceDescription", nameof(defaultService)),
defaultService);
internal static string FormatMethodDescription(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("MethodDescription"), p0);
/// <summary>
/// Missing required option '--{option1}' or '--{option2}'.
/// The qualified name of the service type to retrieve from dependency injection. Default value '{0}'.
/// </summary>
public static string MissingOptions([CanBeNull] object option1, [CanBeNull] object option2)
=> string.Format(
GetString("MissingOptions", nameof(option1), nameof(option2)),
option1, option2);
internal static string ServiceDescription
{
get => GetString("ServiceDescription");
}
/// <summary>
/// The name of the document to pass to the '--method' method. Default value '{defaultDocumentName}'.
/// The qualified name of the service type to retrieve from dependency injection. Default value '{0}'.
/// </summary>
public static string DocumentDescription([CanBeNull] object defaultDocumentName)
=> string.Format(
GetString("DocumentDescription", nameof(defaultDocumentName)),
defaultDocumentName);
internal static string FormatServiceDescription(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("ServiceDescription"), p0);
/// <summary>
/// Using document name '{documentName}'.
/// Missing required option '--{0}' or '--{1}'.
/// </summary>
public static string UsingDocument([CanBeNull] object documentName)
=> string.Format(
GetString("UsingDocument", nameof(documentName)),
documentName);
internal static string MissingOptions
{
get => GetString("MissingOptions");
}
/// <summary>
/// Using method '{method}'.
/// Missing required option '--{0}' or '--{1}'.
/// </summary>
public static string UsingMethod([CanBeNull] object method)
=> string.Format(
GetString("UsingMethod", nameof(method)),
method);
internal static string FormatMissingOptions(object p0, object p1)
=> string.Format(CultureInfo.CurrentCulture, GetString("MissingOptions"), p0, p1);
/// <summary>
/// Using service '{service}'.
/// The name of the document to pass to the '--method' method. Default value '{0}'.
/// </summary>
public static string UsingService([CanBeNull] object service)
=> string.Format(
GetString("UsingService", nameof(service)),
service);
internal static string DocumentDescription
{
get => GetString("DocumentDescription");
}
/// <summary>
/// Using URI '{uri}'.
/// The name of the document to pass to the '--method' method. Default value '{0}'.
/// </summary>
public static string UsingUri([CanBeNull] object uri)
=> string.Format(
GetString("UsingUri", nameof(uri)),
uri);
internal static string FormatDocumentDescription(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("DocumentDescription"), p0);
/// <summary>
/// Method '{method}' of service '{service}' failed to generate document '{documentName}'.
/// Using document name '{0}'.
/// </summary>
public static string MethodInvocationFailed([CanBeNull] object method, [CanBeNull] object service, [CanBeNull] object documentName)
=> string.Format(
GetString("MethodInvocationFailed", nameof(method), nameof(service), nameof(documentName)),
method, service, documentName);
internal static string UsingDocument
{
get => GetString("UsingDocument");
}
/// <summary>
/// Assembly '{assemblyPath}' does not contain an entry point.
/// Using document name '{0}'.
/// </summary>
public static string MissingEntryPoint([CanBeNull] object assemblyPath)
=> string.Format(
GetString("MissingEntryPoint", nameof(assemblyPath)),
assemblyPath);
internal static string FormatUsingDocument(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("UsingDocument"), p0);
/// <summary>
/// Using method '{0}'.
/// </summary>
internal static string UsingMethod
{
get => GetString("UsingMethod");
}
/// <summary>
/// Using method '{0}'.
/// </summary>
internal static string FormatUsingMethod(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("UsingMethod"), p0);
/// <summary>
/// Using service '{0}'.
/// </summary>
internal static string UsingService
{
get => GetString("UsingService");
}
/// <summary>
/// Using service '{0}'.
/// </summary>
internal static string FormatUsingService(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("UsingService"), p0);
/// <summary>
/// Using URI '{0}'.
/// </summary>
internal static string UsingUri
{
get => GetString("UsingUri");
}
/// <summary>
/// Using URI '{0}'.
/// </summary>
internal static string FormatUsingUri(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("UsingUri"), p0);
/// <summary>
/// Method '{0}' of service '{1}' failed to generate document '{2}'.
/// </summary>
internal static string MethodInvocationFailed
{
get => GetString("MethodInvocationFailed");
}
/// <summary>
/// Method '{0}' of service '{1}' failed to generate document '{2}'.
/// </summary>
internal static string FormatMethodInvocationFailed(object p0, object p1, object p2)
=> string.Format(CultureInfo.CurrentCulture, GetString("MethodInvocationFailed"), p0, p1, p2);
/// <summary>
/// Assembly '{0}' does not contain an entry point.
/// </summary>
internal static string MissingEntryPoint
{
get => GetString("MissingEntryPoint");
}
/// <summary>
/// Assembly '{0}' does not contain an entry point.
/// </summary>
internal static string FormatMissingEntryPoint(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("MissingEntryPoint"), p0);
private static string GetString(string name, params string[] formatterNames)
{
var value = _resourceManager.GetString(name);
for (var i = 0; i < formatterNames.Length; i++)
System.Diagnostics.Debug.Assert(value != null);
if (formatterNames != null)
{
value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}");
for (var i = 0; i < formatterNames.Length; i++)
{
value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}");
}
}
return value;
}
}
}

View File

@ -1,6 +0,0 @@
<#
Session["ResourceFile"] = "Resources.resx";
Session["AccessModifier"] = "internal";
Session["NoDiagnostics"] = true;
#>
<#@ include file="..\..\..\tools\Resources.tt" #>

View File

@ -124,7 +124,7 @@
<value>Show JSON output.</value>
</data>
<data name="MissingOption" xml:space="preserve">
<value>Missing required option '--{option}'.</value>
<value>Missing required option '--{0}'.</value>
</data>
<data name="NoColorDescription" xml:space="preserve">
<value>Do not colorize output.</value>
@ -136,22 +136,22 @@
<value>Prefix console output with logging level.</value>
</data>
<data name="UsingApplicationBase" xml:space="preserve">
<value>Using application base '{appBase}'.</value>
<value>Using application base '{0}'.</value>
</data>
<data name="UsingAssembly" xml:space="preserve">
<value>Using assembly '{assembly}'.</value>
<value>Using assembly '{0}'.</value>
</data>
<data name="UsingConfigurationFile" xml:space="preserve">
<value>Using configuration file '{config}'.</value>
<value>Using configuration file '{0}'.</value>
</data>
<data name="VerboseDescription" xml:space="preserve">
<value>Show verbose output.</value>
</data>
<data name="WritingFile" xml:space="preserve">
<value>Writing '{file}'...</value>
<value>Writing '{0}'...</value>
</data>
<data name="UsingWorkingDirectory" xml:space="preserve">
<value>Using working directory '{workingDirectory}'.</value>
<value>Using working directory '{0}'.</value>
</data>
<data name="ToolsDirectoryDescription" xml:space="preserve">
<value>Location from which inside man was copied (in the .NET Framework case) or loaded.</value>
@ -160,33 +160,33 @@
<value>The URI to download the document from.</value>
</data>
<data name="MethodDescription" xml:space="preserve">
<value>The name of the method to invoke on the '--service' instance. Default value '{defaultMethod}'.</value>
<value>The name of the method to invoke on the '--service' instance. Default value '{0}'.</value>
</data>
<data name="ServiceDescription" xml:space="preserve">
<value>The qualified name of the service type to retrieve from dependency injection. Default value '{defaultService}'.</value>
<value>The qualified name of the service type to retrieve from dependency injection. Default value '{0}'.</value>
</data>
<data name="MissingOptions" xml:space="preserve">
<value>Missing required option '--{option1}' or '--{option2}'.</value>
<value>Missing required option '--{0}' or '--{1}'.</value>
</data>
<data name="DocumentDescription" xml:space="preserve">
<value>The name of the document to pass to the '--method' method. Default value '{defaultDocumentName}'.</value>
<value>The name of the document to pass to the '--method' method. Default value '{0}'.</value>
</data>
<data name="UsingDocument" xml:space="preserve">
<value>Using document name '{documentName}'.</value>
<value>Using document name '{0}'.</value>
</data>
<data name="UsingMethod" xml:space="preserve">
<value>Using method '{method}'.</value>
<value>Using method '{0}'.</value>
</data>
<data name="UsingService" xml:space="preserve">
<value>Using service '{service}'.</value>
<value>Using service '{0}'.</value>
</data>
<data name="UsingUri" xml:space="preserve">
<value>Using URI '{uri}'.</value>
<value>Using URI '{0}'.</value>
</data>
<data name="MethodInvocationFailed" xml:space="preserve">
<value>Method '{method}' of service '{service}' failed to generate document '{documentName}'.</value>
<value>Method '{0}' of service '{1}' failed to generate document '{2}'.</value>
</data>
<data name="MissingEntryPoint" xml:space="preserve">
<value>Assembly '{assemblyPath}' does not contain an entry point.</value>
<value>Assembly '{0}' does not contain an entry point.</value>
</data>
</root>
</root>

View File

@ -7,7 +7,6 @@ using System.IO;
using System.Linq;
using System.Runtime.Versioning;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.Extensions.ApiDescription.Client.Properties;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@ -49,7 +48,7 @@ namespace Microsoft.Extensions.ApiDescription.Client.Commands
_project.Value(),
Resources.NoProject,
Resources.MultipleProjects);
Reporter.WriteVerbose(Resources.UsingProject(projectFile));
Reporter.WriteVerbose(Resources.FormatUsingProject(projectFile));
var project = Project.FromFile(
projectFile,
@ -96,7 +95,7 @@ namespace Microsoft.Extensions.ApiDescription.Client.Commands
if (targetFramework.Version < new Version(2, 0))
{
throw new CommandException(
Resources.NETCoreApp1Project(project.Name, targetFramework.Version));
Resources.FormatNETCoreApp1Project(project.Name, targetFramework.Version));
}
args.Add("exec");
@ -135,11 +134,11 @@ namespace Microsoft.Extensions.ApiDescription.Client.Commands
break;
case ".NETStandard":
throw new CommandException(Resources.NETStandardProject(project.Name));
throw new CommandException(Resources.FormatNETStandardProject(project.Name));
default:
throw new CommandException(
Resources.UnsupportedFramework(project.Name, targetFramework.Identifier));
Resources.FormatUnsupportedFramework(project.Name, targetFramework.Identifier));
}
args.AddRange(_args);
@ -224,14 +223,14 @@ namespace Microsoft.Extensions.ApiDescription.Client.Commands
{
throw new CommandException(
specified
? Resources.NoProjectInDirectory(path)
? Resources.FormatNoProjectInDirectory(path)
: errorWhenNoProject);
}
if (projectFiles.Count != 1)
{
throw new CommandException(
specified
? Resources.MultipleProjectsInDirectory(path)
? Resources.FormatMultipleProjectsInDirectory(path)
: errorWhenMultipleProjects);
}

View File

@ -4,7 +4,6 @@
using System;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.Extensions.ApiDescription.Client.Commands;
using Microsoft.Extensions.ApiDescription.Client.Properties;
namespace Microsoft.Extensions.ApiDescription.Client
{

View File

@ -5,7 +5,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Extensions.ApiDescription.Client.Properties;
using IODirectory = System.IO.Directory;
namespace Microsoft.Extensions.ApiDescription.Client
@ -82,7 +81,7 @@ namespace Microsoft.Extensions.ApiDescription.Client
{
using (var output = File.OpenWrite(propsPath))
{
Reporter.WriteVerbose(Resources.WritingFile(propsPath));
Reporter.WriteVerbose(Resources.FormatWritingFile(propsPath));
input.CopyTo(output);
}
}
@ -93,7 +92,7 @@ namespace Microsoft.Extensions.ApiDescription.Client
using (var output = File.OpenWrite(targetsPath))
{
// NB: Copy always in case it changes
Reporter.WriteVerbose(Resources.WritingFile(targetsPath));
Reporter.WriteVerbose(Resources.FormatWritingFile(targetsPath));
input.CopyTo(output);
}
}
@ -171,17 +170,17 @@ namespace Microsoft.Extensions.ApiDescription.Client
if (string.IsNullOrEmpty(project.AssemblyPath))
{
throw new CommandException(Resources.GetMetadataValueFailed(nameof(AssemblyPath), "TargetPath"));
throw new CommandException(Resources.FormatGetMetadataValueFailed(nameof(AssemblyPath), "TargetPath"));
}
if (string.IsNullOrEmpty(project.Directory))
{
throw new CommandException(Resources.GetMetadataValueFailed(nameof(Directory), "ProjectDir"));
throw new CommandException(Resources.FormatGetMetadataValueFailed(nameof(Directory), "ProjectDir"));
}
if (string.IsNullOrEmpty(project.OutputPath))
{
throw new CommandException(Resources.GetMetadataValueFailed(nameof(OutputPath), "OutDir"));
throw new CommandException(Resources.FormatGetMetadataValueFailed(nameof(OutputPath), "OutDir"));
}
if (!Path.IsPathRooted(project.Directory))

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.Extensions.ApiDescription.Client.Properties;
namespace Microsoft.Extensions.ApiDescription.Client
{

View File

@ -1,179 +1,338 @@
// <auto-generated />
using System;
using System.Reflection;
using System.Resources;
using JetBrains.Annotations;
namespace Microsoft.Extensions.ApiDescription.Client.Properties
namespace Microsoft.Extensions.ApiDescription.Client
{
/// <summary>
/// This API supports the GetDocument infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
using System.Globalization;
using System.Reflection;
using System.Resources;
internal static class Resources
{
private static readonly ResourceManager _resourceManager
= new ResourceManager("Microsoft.Extensions.ApiDescription.Client.Properties.Resources", typeof(Resources).GetTypeInfo().Assembly);
= new ResourceManager("Microsoft.Extensions.ApiDescription.Client.Resources", typeof(Resources).GetTypeInfo().Assembly);
/// <summary>
/// The configuration to use.
/// The configuration to use.
/// </summary>
public static string ConfigurationDescription
internal static string ConfigurationDescription
{
get => GetString("ConfigurationDescription");
}
/// <summary>
/// The configuration to use.
/// </summary>
internal static string FormatConfigurationDescription()
=> GetString("ConfigurationDescription");
/// <summary>
/// dotnet-getdocument
/// dotnet-getdocument
/// </summary>
public static string CommandFullName
internal static string CommandFullName
{
get => GetString("CommandFullName");
}
/// <summary>
/// dotnet-getdocument
/// </summary>
internal static string FormatCommandFullName()
=> GetString("CommandFullName");
/// <summary>
/// The target framework.
/// The target framework.
/// </summary>
public static string FrameworkDescription
internal static string FrameworkDescription
{
get => GetString("FrameworkDescription");
}
/// <summary>
/// The target framework.
/// </summary>
internal static string FormatFrameworkDescription()
=> GetString("FrameworkDescription");
/// <summary>
/// Unable to retrieve project metadata. If you are using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, use the --msbuildprojectextensionspath option.
/// Unable to retrieve project metadata. If you are using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, use the --msbuildprojectextensionspath option.
/// </summary>
public static string GetMetadataFailed
internal static string GetMetadataFailed
{
get => GetString("GetMetadataFailed");
}
/// <summary>
/// Unable to retrieve project metadata. If you are using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, use the --msbuildprojectextensionspath option.
/// </summary>
internal static string FormatGetMetadataFailed()
=> GetString("GetMetadataFailed");
/// <summary>
/// More than one project was found in the current working directory. Use the --project option.
/// More than one project was found in the current working directory. Use the --project option.
/// </summary>
public static string MultipleProjects
internal static string MultipleProjects
{
get => GetString("MultipleProjects");
}
/// <summary>
/// More than one project was found in the current working directory. Use the --project option.
/// </summary>
internal static string FormatMultipleProjects()
=> GetString("MultipleProjects");
/// <summary>
/// More than one project was found in directory '{projectDirectory}'. Specify one using its file name.
/// More than one project was found in directory '{0}'. Specify one using its file name.
/// </summary>
public static string MultipleProjectsInDirectory([CanBeNull] object projectDirectory)
=> string.Format(
GetString("MultipleProjectsInDirectory", nameof(projectDirectory)),
projectDirectory);
internal static string MultipleProjectsInDirectory
{
get => GetString("MultipleProjectsInDirectory");
}
/// <summary>
/// Project '{Project}' targets framework '.NETCoreApp' version '{targetFrameworkVersion}'. This version of the dotnet-getdocument tool only supports version 2.0 or higher.
/// More than one project was found in directory '{0}'. Specify one using its file name.
/// </summary>
public static string NETCoreApp1Project([CanBeNull] object Project, [CanBeNull] object targetFrameworkVersion)
=> string.Format(
GetString("NETCoreApp1Project", nameof(Project), nameof(targetFrameworkVersion)),
Project, targetFrameworkVersion);
internal static string FormatMultipleProjectsInDirectory(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("MultipleProjectsInDirectory"), p0);
/// <summary>
/// Project '{Project}' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. To use the dotnet-getdocument tool with this project, add an executable project targeting .NET Core or .NET Framework that references this project and specify it using the --project option; or, update this project to target .NET Core and / or .NET Framework.
/// Project '{0}' targets framework '.NETCoreApp' version '{1}'. This version of the dotnet-getdocument tool only supports version 2.0 or higher.
/// </summary>
public static string NETStandardProject([CanBeNull] object Project)
=> string.Format(
GetString("NETStandardProject", nameof(Project)),
Project);
internal static string NETCoreApp1Project
{
get => GetString("NETCoreApp1Project");
}
/// <summary>
/// Do not colorize output.
/// Project '{0}' targets framework '.NETCoreApp' version '{1}'. This version of the dotnet-getdocument tool only supports version 2.0 or higher.
/// </summary>
public static string NoColorDescription
internal static string FormatNETCoreApp1Project(object p0, object p1)
=> string.Format(CultureInfo.CurrentCulture, GetString("NETCoreApp1Project"), p0, p1);
/// <summary>
/// Project '{0}' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. To use the dotnet-getdocument tool with this project, add an executable project targeting .NET Core or .NET Framework that references this project and specify it using the --project option; or, update this project to target .NET Core and / or .NET Framework.
/// </summary>
internal static string NETStandardProject
{
get => GetString("NETStandardProject");
}
/// <summary>
/// Project '{0}' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. To use the dotnet-getdocument tool with this project, add an executable project targeting .NET Core or .NET Framework that references this project and specify it using the --project option; or, update this project to target .NET Core and / or .NET Framework.
/// </summary>
internal static string FormatNETStandardProject(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("NETStandardProject"), p0);
/// <summary>
/// Do not colorize output.
/// </summary>
internal static string NoColorDescription
{
get => GetString("NoColorDescription");
}
/// <summary>
/// Do not colorize output.
/// </summary>
internal static string FormatNoColorDescription()
=> GetString("NoColorDescription");
/// <summary>
/// No project was found. Change the current working directory or use the --project option.
/// No project was found. Change the current working directory or use the --project option.
/// </summary>
public static string NoProject
internal static string NoProject
{
get => GetString("NoProject");
}
/// <summary>
/// No project was found. Change the current working directory or use the --project option.
/// </summary>
internal static string FormatNoProject()
=> GetString("NoProject");
/// <summary>
/// No project was found in directory '{projectDirectory}'.
/// No project was found in directory '{0}'.
/// </summary>
public static string NoProjectInDirectory([CanBeNull] object projectDirectory)
=> string.Format(
GetString("NoProjectInDirectory", nameof(projectDirectory)),
projectDirectory);
internal static string NoProjectInDirectory
{
get => GetString("NoProjectInDirectory");
}
/// <summary>
/// Prefix output with level.
/// No project was found in directory '{0}'.
/// </summary>
public static string PrefixDescription
internal static string FormatNoProjectInDirectory(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("NoProjectInDirectory"), p0);
/// <summary>
/// Prefix output with level.
/// </summary>
internal static string PrefixDescription
{
get => GetString("PrefixDescription");
}
/// <summary>
/// Prefix output with level.
/// </summary>
internal static string FormatPrefixDescription()
=> GetString("PrefixDescription");
/// <summary>
/// The project to use.
/// The project to use.
/// </summary>
public static string ProjectDescription
internal static string ProjectDescription
{
get => GetString("ProjectDescription");
}
/// <summary>
/// The project to use.
/// </summary>
internal static string FormatProjectDescription()
=> GetString("ProjectDescription");
/// <summary>
/// The MSBuild project extensions path. Defaults to "obj".
/// The MSBuild project extensions path. Defaults to "obj".
/// </summary>
public static string ProjectExtensionsDescription
internal static string ProjectExtensionsDescription
{
get => GetString("ProjectExtensionsDescription");
}
/// <summary>
/// The MSBuild project extensions path. Defaults to "obj".
/// </summary>
internal static string FormatProjectExtensionsDescription()
=> GetString("ProjectExtensionsDescription");
/// <summary>
/// The runtime identifier to use.
/// The runtime identifier to use.
/// </summary>
public static string RuntimeDescription
internal static string RuntimeDescription
{
get => GetString("RuntimeDescription");
}
/// <summary>
/// The runtime identifier to use.
/// </summary>
internal static string FormatRuntimeDescription()
=> GetString("RuntimeDescription");
/// <summary>
/// Project '{Project}' targets framework '{targetFramework}'. The dotnet-getdocument tool does not support this framework.
/// Project '{0}' targets framework '{1}'. The dotnet-getdocument tool does not support this framework.
/// </summary>
public static string UnsupportedFramework([CanBeNull] object Project, [CanBeNull] object targetFramework)
=> string.Format(
GetString("UnsupportedFramework", nameof(Project), nameof(targetFramework)),
Project, targetFramework);
internal static string UnsupportedFramework
{
get => GetString("UnsupportedFramework");
}
/// <summary>
/// Using project '{project}'.
/// Project '{0}' targets framework '{1}'. The dotnet-getdocument tool does not support this framework.
/// </summary>
public static string UsingProject([CanBeNull] object project)
=> string.Format(
GetString("UsingProject", nameof(project)),
project);
internal static string FormatUnsupportedFramework(object p0, object p1)
=> string.Format(CultureInfo.CurrentCulture, GetString("UnsupportedFramework"), p0, p1);
/// <summary>
/// Show verbose output.
/// Using project '{0}'.
/// </summary>
public static string VerboseDescription
internal static string UsingProject
{
get => GetString("UsingProject");
}
/// <summary>
/// Using project '{0}'.
/// </summary>
internal static string FormatUsingProject(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("UsingProject"), p0);
/// <summary>
/// Show verbose output.
/// </summary>
internal static string VerboseDescription
{
get => GetString("VerboseDescription");
}
/// <summary>
/// Show verbose output.
/// </summary>
internal static string FormatVerboseDescription()
=> GetString("VerboseDescription");
/// <summary>
/// Writing '{file}'...
/// Writing '{0}'...
/// </summary>
public static string WritingFile([CanBeNull] object file)
=> string.Format(
GetString("WritingFile", nameof(file)),
file);
internal static string WritingFile
{
get => GetString("WritingFile");
}
/// <summary>
/// Project output not found and --no-build was specified. Project must be up-to-date when using the --no-build option.
/// Writing '{0}'...
/// </summary>
public static string MustBuild
internal static string FormatWritingFile(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("WritingFile"), p0);
/// <summary>
/// Project output not found and --no-build was specified. Project must be up-to-date when using the --no-build option.
/// </summary>
internal static string MustBuild
{
get => GetString("MustBuild");
}
/// <summary>
/// Project output not found and --no-build was specified. Project must be up-to-date when using the --no-build option.
/// </summary>
internal static string FormatMustBuild()
=> GetString("MustBuild");
/// <summary>
/// The file to write the result to.
/// The file to write the result to.
/// </summary>
public static string OutputDescription
internal static string OutputDescription
{
get => GetString("OutputDescription");
}
/// <summary>
/// The file to write the result to.
/// </summary>
internal static string FormatOutputDescription()
=> GetString("OutputDescription");
/// <summary>
/// Unable to retrieve '{properrty}' project metadata. Ensure '{msbuildProperty}' is set.
/// Unable to retrieve '{0}' project metadata. Ensure '{1}' is set.
/// </summary>
public static string GetMetadataValueFailed([CanBeNull] object properrty, [CanBeNull] object msbuildProperty)
=> string.Format(
GetString("GetMetadataValueFailed", nameof(properrty), nameof(msbuildProperty)),
properrty, msbuildProperty);
internal static string GetMetadataValueFailed
{
get => GetString("GetMetadataValueFailed");
}
/// <summary>
/// Unable to retrieve '{0}' project metadata. Ensure '{1}' is set.
/// </summary>
internal static string FormatGetMetadataValueFailed(object p0, object p1)
=> string.Format(CultureInfo.CurrentCulture, GetString("GetMetadataValueFailed"), p0, p1);
private static string GetString(string name, params string[] formatterNames)
{
var value = _resourceManager.GetString(name);
for (var i = 0; i < formatterNames.Length; i++)
System.Diagnostics.Debug.Assert(value != null);
if (formatterNames != null)
{
value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}");
for (var i = 0; i < formatterNames.Length; i++)
{
value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}");
}
}
return value;
}
}
}

View File

@ -1,6 +0,0 @@
<#
Session["ResourceFile"] = "Resources.resx";
Session["AccessModifier"] = "internal";
Session["NoDiagnostics"] = true;
#>
<#@ include file="..\..\..\tools\Resources.tt" #>

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
@ -133,13 +133,13 @@
<value>More than one project was found in the current working directory. Use the --project option.</value>
</data>
<data name="MultipleProjectsInDirectory" xml:space="preserve">
<value>More than one project was found in directory '{projectDirectory}'. Specify one using its file name.</value>
<value>More than one project was found in directory '{0}'. Specify one using its file name.</value>
</data>
<data name="NETCoreApp1Project" xml:space="preserve">
<value>Project '{Project}' targets framework '.NETCoreApp' version '{targetFrameworkVersion}'. This version of the dotnet-getdocument tool only supports version 2.0 or higher.</value>
<value>Project '{0}' targets framework '.NETCoreApp' version '{1}'. This version of the dotnet-getdocument tool only supports version 2.0 or higher.</value>
</data>
<data name="NETStandardProject" xml:space="preserve">
<value>Project '{Project}' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. To use the dotnet-getdocument tool with this project, add an executable project targeting .NET Core or .NET Framework that references this project and specify it using the --project option; or, update this project to target .NET Core and / or .NET Framework.</value>
<value>Project '{0}' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. To use the dotnet-getdocument tool with this project, add an executable project targeting .NET Core or .NET Framework that references this project and specify it using the --project option; or, update this project to target .NET Core and / or .NET Framework.</value>
</data>
<data name="NoColorDescription" xml:space="preserve">
<value>Do not colorize output.</value>
@ -148,7 +148,7 @@
<value>No project was found. Change the current working directory or use the --project option.</value>
</data>
<data name="NoProjectInDirectory" xml:space="preserve">
<value>No project was found in directory '{projectDirectory}'.</value>
<value>No project was found in directory '{0}'.</value>
</data>
<data name="PrefixDescription" xml:space="preserve">
<value>Prefix output with level.</value>
@ -163,16 +163,16 @@
<value>The runtime identifier to use.</value>
</data>
<data name="UnsupportedFramework" xml:space="preserve">
<value>Project '{Project}' targets framework '{targetFramework}'. The dotnet-getdocument tool does not support this framework.</value>
<value>Project '{0}' targets framework '{1}'. The dotnet-getdocument tool does not support this framework.</value>
</data>
<data name="UsingProject" xml:space="preserve">
<value>Using project '{project}'.</value>
<value>Using project '{0}'.</value>
</data>
<data name="VerboseDescription" xml:space="preserve">
<value>Show verbose output.</value>
</data>
<data name="WritingFile" xml:space="preserve">
<value>Writing '{file}'...</value>
<value>Writing '{0}'...</value>
</data>
<data name="MustBuild" xml:space="preserve">
<value>Project output not found and --no-build was specified. Project must be up-to-date when using the --no-build option.</value>
@ -181,6 +181,6 @@
<value>The file to write the result to.</value>
</data>
<data name="GetMetadataValueFailed" xml:space="preserve">
<value>Unable to retrieve '{properrty}' project metadata. Ensure '{msbuildProperty}' is set.</value>
<value>Unable to retrieve '{0}' project metadata. Ensure '{1}' is set.</value>
</data>
</root>
</root>

View File

@ -41,25 +41,6 @@
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
</ItemGroup>
<ItemGroup>
<None Update="Properties/Resources.Designer.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties/Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.Designer.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<!-- Additional files to be code signed -->
<SignedPackageFile Include="tools/netcoreapp2.1/any/tools/net461/any/GetDocument.Insider.exe" Certificate="$(AssemblySigningCertName)" />

View File

@ -1,226 +0,0 @@
<#@ template hostspecific="true" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Windows.Forms" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.ComponentModel.Design" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Resources" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ import namespace="EnvDTE" #>
<#
var model = LoadResources();
#>
// <auto-generated />
using System;
using System.Reflection;
using System.Resources;
using JetBrains.Annotations;
<#
if (!model.NoDiagnostics)
{
#>
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Logging;
<#
}
#>
namespace <#= model.Namespace #>
{
/// <summary>
/// This API supports the GetDocument infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
<#= model.AccessModifier #> static class <#= model.Class #>
{
private static readonly ResourceManager _resourceManager
= new ResourceManager("<#= model.ResourceName #>", typeof(<#= model.Class #>).GetTypeInfo().Assembly);
<#
foreach (var resource in model.Resources)
{
#>
/// <summary>
<#
foreach (var line in Lines(resource.Value))
{
#>
/// <#= Xml(line) #>
<#
}
#>
/// </summary>
<#
if (resource.ForLogging)
{
if (resource.Types.Count() > 6)
{
#>
public static readonly FallbackEventDefinition <#= resource.Name #>
= new FallbackEventDefinition(
<#= resource.EventId #>,
LogLevel.<#= resource.Level #>,
"<#= resource.EventId #>",
_resourceManager.GetString("<#= resource.Name #>"));
<#
}
else
{
var genericTypes = resource.Types.Any() ? ("<" + List(resource.Types) + ">") : "";
#>
public static readonly EventDefinition<#= genericTypes #> <#= resource.Name #>
= new EventDefinition<#= genericTypes #>(
<#= resource.EventId #>,
LogLevel.<#= resource.Level #>,
"<#= resource.EventId #>",
LoggerMessage.Define<#= genericTypes #>(
LogLevel.<#= resource.Level #>,
<#= resource.EventId #>,
_resourceManager.GetString("<#= resource.Name #>")));
<#
}
}
else
{
if (resource.Parameters.Any())
{
#>
public static string <#= resource.Name #>(<#= List("[CanBeNull] object ", resource.Parameters) #>)
=> string.Format(
GetString("<#= resource.Name #>", <#= List("nameof(", resource.Parameters, ")") #>),
<#= List(resource.Parameters) #>);
<#
}
else
{
#>
public static string <#= resource.Name #>
=> GetString("<#= resource.Name #>");
<#
}
}
}
#>
private static string GetString(string name, params string[] formatterNames)
{
var value = _resourceManager.GetString(name);
for (var i = 0; i < formatterNames.Length; i++)
{
value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}");
}
return value;
}
}
}
<#+
ResourceFile LoadResources()
{
var result = new ResourceFile();
if (Session.ContainsKey("AccessModifier"))
{
result.AccessModifier = (string)Session["AccessModifier"];
};
var services = (IServiceProvider)Host;
var dte = (DTE)services.GetService(typeof(DTE));
if (!Session.TryGetValue("NoDiagnostics", out var noDiagnostics))
{
noDiagnostics = false;
}
result.NoDiagnostics = (bool)noDiagnostics;
var resourceFile = (string)Session["ResourceFile"];
if (!Path.IsPathRooted(resourceFile))
{
resourceFile = Host.ResolvePath(resourceFile);
}
var resourceProjectItem = dte.Solution.FindProjectItem(resourceFile);
var templateProjectItem = dte.Solution.FindProjectItem(Host.TemplateFile);
var project = templateProjectItem.ContainingProject;
var rootNamespace = (string)project.Properties.Item("RootNamespace").Value;
var resourceDir = Path.GetDirectoryName(resourceFile);
var projectDir = (string)project.Properties.Item("FullPath").Value;
var resourceNamespace = rootNamespace + "." + resourceDir.Substring(projectDir.Length)
.Replace(Path.DirectorySeparatorChar, '.');
result.Namespace = (string)resourceProjectItem.Properties.Item("CustomToolNamespace")?.Value;
if (string.IsNullOrEmpty(result.Namespace))
{
result.Namespace = resourceNamespace;
}
result.Class = Path.GetFileNameWithoutExtension(resourceFile);
result.ResourceName = resourceNamespace + "." + result.Class;
using (var reader = new ResXResourceReader(resourceFile))
{
reader.UseResXDataNodes = true;
result.Resources = Enumerable.ToList(
from DictionaryEntry r in reader
select new Resource((ResXDataNode)r.Value));
}
return result;
}
IEnumerable<string> Lines(string value)
=> value.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
string Xml(string value)
=> value.Replace("<", "&lt;").Replace(">", "&gt;");
string List(IEnumerable<string> items)
=> List(null, items);
string List(string prefix, IEnumerable<string> items, string suffix = null)
=> string.Join(", ", items.Select(i => prefix + i + suffix));
class ResourceFile
{
public string Namespace { get; set; }
public string AccessModifier { get; set; } = "public";
public string Class { get; set; }
public string ResourceName { get; set; }
public IEnumerable<Resource> Resources { get; set; }
public bool NoDiagnostics { get; set; }
}
class Resource
{
public Resource(ResXDataNode node)
{
Name = node.Name;
Value = (string)node.GetValue((ITypeResolutionService)null);
Parameters = Regex.Matches(Value, @"\{(\w+)\}")
.Cast<Match>()
.Select(m => m.Groups[1].Value)
.Distinct()
.ToList();
var eventInfo = node.Comment.Split(' ');
Level = eventInfo.FirstOrDefault() ?? "BadLevel";
EventId = eventInfo.Skip(1).FirstOrDefault() ?? "BadEventId";
Types = eventInfo.Skip(2).ToList();
}
public string Name { get; }
public string Value { get; }
public string EventId { get; }
public string Level { get; }
public bool ForLogging => Name.StartsWith("Log");
public IEnumerable<string> Parameters { get; }
public IEnumerable<string> Types { get; }
}
#>