Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/Framework.UnitTests/AbsolutePath_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Build.Shared;
using Shouldly;
using Xunit;
using Xunit.NetCore.Extensions;

namespace Microsoft.Build.UnitTests
{
Expand Down Expand Up @@ -47,18 +48,22 @@ public void AbsolutePath_FromAbsolutePath_ShouldPreservePath()
[Theory]
[InlineData(null)]
[InlineData("")]
[UseInvariantCulture]
public void AbsolutePath_NullOrEmpty_ShouldThrow(string? path)
{
Should.Throw<ArgumentException>(() => new AbsolutePath(path!));
var exception = Should.Throw<ArgumentException>(() => new AbsolutePath(path!));
exception.Message.ShouldContain("Path must not be null or empty");
}

[Theory]
[InlineData(null)]
[InlineData("")]
[UseInvariantCulture]
public void AbsolutePath_NullOrEmptyWithBasePath_ShouldThrow(string? path)
{
var basePath = GetTestBasePath();
Should.Throw<ArgumentException>(() => new AbsolutePath(path!, basePath));
var exception = Should.Throw<ArgumentException>(() => new AbsolutePath(path!, basePath));
exception.Message.ShouldContain("Path must not be null or empty");
}

[Theory]
Expand Down Expand Up @@ -213,5 +218,13 @@ public void AbsolutePath_UnixPathValidation_ShouldAcceptOnlyTrueAbsolutePaths(st
{
ValidatePathAcceptance(path, shouldBeAccepted);
}

[WindowsOnlyFact]
[UseInvariantCulture]
public void AbsolutePath_NotRooted_ShouldThrowWithLocalizedMessage()
{
var exception = Should.Throw<ArgumentException>(() => new AbsolutePath("relative/path"));
exception.Message.ShouldContain("Path must be rooted");
}
}
}
7 changes: 7 additions & 0 deletions src/Framework/Microsoft.Build.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,11 @@
<ItemGroup>
<RCResourceFile Include="native.rc" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resources\Strings.resx">
<LogicalName>$(AssemblyName).Strings.resources</LogicalName>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions src/Framework/PathHelpers/AbsolutePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ private static void ValidatePath(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentException("Path must not be null or empty.", nameof(path));
throw new ArgumentException(FrameworkResources.GetString("PathMustNotBeNullOrEmpty"), nameof(path));
}

// Path.IsPathFullyQualified is not available in .NET Standard 2.0
// in .NET Framework it's provided by package and in .NET it's built-in
#if NETFRAMEWORK || NET
if (!Path.IsPathFullyQualified(path))
{
throw new ArgumentException("Path must be rooted.", nameof(path));
throw new ArgumentException(FrameworkResources.GetString("PathMustBeRooted"), nameof(path));
}
#endif
}
Expand All @@ -110,15 +110,15 @@ public AbsolutePath(string path, AbsolutePath basePath)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentException("Path must not be null or empty.", nameof(path));
throw new ArgumentException(FrameworkResources.GetString("PathMustNotBeNullOrEmpty"), nameof(path));
}

// This function should not throw when path has illegal characters.
// For .NET Framework, Microsoft.IO.Path.Combine should be used instead of System.IO.Path.Combine to achieve it.
// For .NET Core, System.IO.Path.Combine already does not throw in this case.
Value = Path.Combine(basePath.Value, path);
OriginalValue = path;
}
}

/// <summary>
/// Implicitly converts an AbsolutePath to a string.
Expand Down
40 changes: 40 additions & 0 deletions src/Framework/Resources/AssemblyResources.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Globalization;
using System.Reflection;
using System.Resources;

namespace Microsoft.Build.Framework
{
/// <summary>
/// This class provides access to the Framework assembly's resources.
/// </summary>
/// <remarks>
/// Named FrameworkResources (not AssemblyResources) to avoid conflicts with
/// Microsoft.Build.Shared.AssemblyResources which is visible via InternalsVisibleTo.
/// </remarks>
internal static class FrameworkResources
{
/// <summary>
/// The assembly's primary resources.
/// </summary>
private static readonly ResourceManager s_resources = new ResourceManager("Microsoft.Build.Framework.Strings", typeof(FrameworkResources).GetTypeInfo().Assembly);

/// <summary>
/// Loads the specified resource string.
/// </summary>
/// <remarks>This method is thread-safe.</remarks>
/// <param name="name">The name of the string resource to load.</param>
/// <returns>The resource string.</returns>
internal static string GetString(string name)
{
// NOTE: the ResourceManager.GetString() method is thread-safe
string? resource = s_resources.GetString(name, CultureInfo.CurrentUICulture);

FrameworkErrorUtilities.VerifyThrow(resource != null, $"Missing resource '{name}'");

return resource!;
}
}
}
126 changes: 126 additions & 0 deletions src/Framework/Resources/Strings.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
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
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<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
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
mimetype set.

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
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
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
: 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
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="PathMustNotBeNullOrEmpty" xml:space="preserve">
<value>Path must not be null or empty.</value>
</data>
<data name="PathMustBeRooted" xml:space="preserve">
<value>Path must be rooted.</value>
</data>
</root>
17 changes: 17 additions & 0 deletions src/Framework/Resources/xlf/Strings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/Framework/Resources/xlf/Strings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/Framework/Resources/xlf/Strings.en.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/Framework/Resources/xlf/Strings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/Framework/Resources/xlf/Strings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/Framework/Resources/xlf/Strings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/Framework/Resources/xlf/Strings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading