Switch to resx source generator

This commit is contained in:
Andrew Arnott 2023-04-08 17:11:11 -06:00
Родитель 918d1f3610
Коммит 1d47ab9068
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: F33A420C60ED9C6F
9 изменённых файлов: 30 добавлений и 282 удалений

Просмотреть файл

@ -8,4 +8,20 @@
<!-- Avoid compile error about missing namespace when combining ImplicitUsings with .NET Framework target frameworks. -->
<Using Remove="System.Net.Http" Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'" />
</ItemGroup>
<!-- Enable code generation for resx files. -->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.ResxSourceGenerator" PrivateAssets="all" />
<CodeGenerationEmbeddedResource Include="@(EmbeddedResource)" Exclude="**\*.??-??.resx;**\*.??.resx" />
<NonCodeGenerationEmbeddedResource Include="@(EmbeddedResource)" Exclude="@(CodeGenerationEmbeddedResource)" />
<AdditionalFiles Include="@(CodeGenerationEmbeddedResource)" EmitFormatMethods="true" />
</ItemGroup>
<!-- Special handling for embedded resources to show as nested in Solution Explorer -->
<ItemGroup>
<!-- Localized embedded resources are just dependent on the parent RESX -->
<EmbeddedResource Update="**\*.??-??.resx" DependentUpon="$([System.IO.Path]::ChangeExtension($([System.IO.Path]::GetFileNameWithoutExtension(%(Identity))), '.resx'))" />
<EmbeddedResource Update="**\*.??.resx" DependentUpon="$([System.IO.Path]::ChangeExtension($([System.IO.Path]::GetFileNameWithoutExtension(%(Identity))), '.resx'))" />
</ItemGroup>
</Project>

Просмотреть файл

@ -7,6 +7,7 @@
<MicroBuildVersion>2.0.115</MicroBuildVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.CodeAnalysis.ResxSourceGenerator" Version="3.3.3-beta1.21417.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageVersion Include="Microsoft.VisualStudio.Internal.MicroBuild.NonShipping" Version="$(MicroBuildVersion)" />
<PackageVersion Include="Moq" Version="4.18.4" />

Просмотреть файл

@ -264,7 +264,7 @@ public static partial class Assumes
if (component is null)
{
Type coreType = PrivateErrorHelpers.TrimGenericWrapper(typeof(T), typeof(Lazy<>));
Fail(string.Format(CultureInfo.CurrentCulture, Strings.ServiceMissing, coreType.FullName));
Fail(Strings.FormatServiceMissing(coreType.FullName!));
}
}

Просмотреть файл

@ -10,17 +10,4 @@
<ItemGroup>
<None Include="$(RepoRootPath)README.md" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Strings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Update="Strings.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
</ItemGroup>
</Project>

Просмотреть файл

@ -26,7 +26,7 @@ public static class Report
if (part is null)
{
Type coreType = PrivateErrorHelpers.TrimGenericWrapper(typeof(T), typeof(Lazy<>));
Fail(Strings.ServiceMissing, coreType.FullName);
Fail(Strings.FormatServiceMissing(coreType.FullName!));
}
}

Просмотреть файл

@ -140,7 +140,7 @@ public static class Requires
if (value.Length == 0 || value[0] == '\0')
{
throw new ArgumentException(Format(Strings.Argument_EmptyString, parameterName), parameterName);
throw new ArgumentException(Strings.FormatArgument_EmptyString(parameterName!), parameterName);
}
}
@ -163,7 +163,7 @@ public static class Requires
if (value.Length == 0 || value[0] == '\0')
{
throw new ArgumentException(Format(Strings.Argument_EmptyString, parameterName), parameterName);
throw new ArgumentException(Strings.FormatArgument_EmptyString(parameterName!), parameterName);
}
if (string.IsNullOrWhiteSpace(value))
@ -195,7 +195,7 @@ public static class Requires
{
if (!enumerator.MoveNext())
{
throw new ArgumentException(Format(Strings.Argument_EmptyArray, parameterName), parameterName);
throw new ArgumentException(Strings.FormatArgument_EmptyArray(parameterName!), parameterName);
}
}
}
@ -236,7 +236,7 @@ public static class Requires
if (isEmpty)
{
throw new ArgumentException(Format(Strings.Argument_EmptyArray, parameterName), parameterName);
throw new ArgumentException(Strings.FormatArgument_EmptyArray(parameterName!), parameterName);
}
}
@ -261,7 +261,7 @@ public static class Requires
if (values.Count == 0)
{
throw new ArgumentException(Format(Strings.Argument_EmptyArray, parameterName), parameterName);
throw new ArgumentException(Strings.FormatArgument_EmptyArray(parameterName!), parameterName);
}
}
@ -292,13 +292,13 @@ public static class Requires
if (value is null)
{
throw new ArgumentException(Format(Strings.Argument_NullElement, parameterName), parameterName);
throw new ArgumentException(Strings.FormatArgument_NullElement(parameterName!), parameterName);
}
}
if (!hasElements)
{
throw new ArgumentException(Format(Strings.Argument_EmptyArray, parameterName), parameterName);
throw new ArgumentException(Strings.FormatArgument_EmptyArray(parameterName!), parameterName);
}
}
@ -319,7 +319,7 @@ public static class Requires
{
if (value is null)
{
throw new ArgumentException(Format(Strings.Argument_NullElement, parameterName), parameterName);
throw new ArgumentException(Strings.FormatArgument_NullElement(parameterName!), parameterName);
}
}
}
@ -336,7 +336,7 @@ public static class Requires
{
if (value == Guid.Empty)
{
throw new ArgumentException(Format(Strings.Argument_EmptyGuid, parameterName), parameterName);
throw new ArgumentException(Strings.FormatArgument_EmptyGuid(parameterName!), parameterName);
}
}
@ -535,7 +535,7 @@ public static class Requires
}
else
{
throw new InvalidEnumArgumentException(Format(Strings.Argument_NotEnum, parameterName, value, typeof(TEnum).FullName));
throw new InvalidEnumArgumentException(Strings.FormatArgument_NotEnum(parameterName!, value, typeof(TEnum).FullName!));
}
}
}
@ -555,7 +555,7 @@ public static class Requires
var defaultValue = default(T);
if (defaultValue.Equals(value))
{
throw new ArgumentException(PrivateErrorHelpers.Format(Strings.Argument_StructIsDefault, parameterName, typeof(T).FullName), parameterName);
throw new ArgumentException(Strings.FormatArgument_StructIsDefault(parameterName!, typeof(T).FullName!), parameterName);
}
}

Просмотреть файл

@ -1,144 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Microsoft {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Strings {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Strings() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.Strings", typeof(Strings).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to &apos;{0}&apos; must contain at least one element..
/// </summary>
internal static string Argument_EmptyArray {
get {
return ResourceManager.GetString("Argument_EmptyArray", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &apos;{0}&apos; cannot be an empty guid..
/// </summary>
internal static string Argument_EmptyGuid {
get {
return ResourceManager.GetString("Argument_EmptyGuid", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &apos;{0}&apos; cannot be an empty string (&quot;&quot;) or start with the null character..
/// </summary>
internal static string Argument_EmptyString {
get {
return ResourceManager.GetString("Argument_EmptyString", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The value of argument &apos;{0}&apos; ({1}) is invalid for Enum type &apos;{2}&apos;..
/// </summary>
internal static string Argument_NotEnum {
get {
return ResourceManager.GetString("Argument_NotEnum", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &apos;{0}&apos; cannot contain a null (Nothing in Visual Basic) element..
/// </summary>
internal static string Argument_NullElement {
get {
return ResourceManager.GetString("Argument_NullElement", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &apos;{0}&apos; cannot be the default value defined by &apos;{1}&apos;..
/// </summary>
internal static string Argument_StructIsDefault {
get {
return ResourceManager.GetString("Argument_StructIsDefault", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The argument cannot consist entirely of white space characters..
/// </summary>
internal static string Argument_Whitespace {
get {
return ResourceManager.GetString("Argument_Whitespace", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An internal error occurred. Please contact Microsoft Support..
/// </summary>
internal static string InternalExceptionMessage {
get {
return ResourceManager.GetString("InternalExceptionMessage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Cannot find an instance of the {0} service..
/// </summary>
internal static string ServiceMissing {
get {
return ResourceManager.GetString("ServiceMissing", resourceCulture);
}
}
}
}

Просмотреть файл

@ -11,17 +11,4 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.VisualStudio.Validation\Microsoft.VisualStudio.Validation.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="TestStrings.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>TestStrings.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="TestStrings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>TestStrings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

Просмотреть файл

@ -1,99 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Microsoft.VisualStudio.Validation.Tests {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class TestStrings {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal TestStrings() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.VisualStudio.Validation.Tests.TestStrings", typeof(TestStrings).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Error text.
/// </summary>
internal static string SomeError {
get {
return ResourceManager.GetString("SomeError", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Error text {0}.
/// </summary>
internal static string SomeError1Arg {
get {
return ResourceManager.GetString("SomeError1Arg", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Error text {0} {1}.
/// </summary>
internal static string SomeError2Args {
get {
return ResourceManager.GetString("SomeError2Args", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Error text {0} {1} {2}.
/// </summary>
internal static string SomeError3Args {
get {
return ResourceManager.GetString("SomeError3Args", resourceCulture);
}
}
}
}