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
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<SystemReflectionMetadataLoadContextToolsetPackageVersion>9.0.0</SystemReflectionMetadataLoadContextToolsetPackageVersion>
<SystemReflectionMetadataToolsetPackageVersion>9.0.0</SystemReflectionMetadataToolsetPackageVersion>
<SystemDiagnosticsDiagnosticSourceToolsetPackageVersion>9.0.0</SystemDiagnosticsDiagnosticSourceToolsetPackageVersion>
<SystemTextEncodingCodePagesToolsetPackageVersion>8.0.0</SystemTextEncodingCodePagesToolsetPackageVersion>
<SystemTextJsonToolsetPackageVersion>9.0.0</SystemTextJsonToolsetPackageVersion>
<SystemThreadingTasksExtensionsToolsetPackageVersion>4.5.4</SystemThreadingTasksExtensionsToolsetPackageVersion>
<SystemResourcesExtensionsToolsetPackageVersion>8.0.0</SystemResourcesExtensionsToolsetPackageVersion>
Expand Down
20 changes: 20 additions & 0 deletions src/Cli/Microsoft.DotNet.FileBasedPrograms/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Note: this editorconfig is *only* used during local builds.
# The actual source package will include 'eng\config\SourcePackage.editorconfig' or similar per-TFM config to control analyzer behavior at the consumption side.

[*.cs]
# IDE0240: Remove redundant nullable directive
# The directive needs to be included since all sources in a source package are considered generated code
# when referenced from a project via package reference.
dotnet_diagnostic.IDE0240.severity = none

dotnet_diagnostic.RS0051.severity = warning # Add internal types and members to the declared API
dotnet_diagnostic.RS0052.severity = warning # Remove deleted types and members from the declared internal API
dotnet_diagnostic.RS0053.severity = warning # The contents of the internal API files are invalid
dotnet_diagnostic.RS0054.severity = warning # Do not duplicate symbols in internal API files
dotnet_diagnostic.RS0055.severity = warning # Annotate nullability of internal types and members in the declared API
dotnet_diagnostic.RS0056.severity = warning # Enable tracking of nullability of reference types in the declared API
dotnet_diagnostic.RS0057.severity = warning # Internal members should not use oblivious types
dotnet_diagnostic.RS0058.severity = warning # Missing shipped or unshipped internal API file
dotnet_diagnostic.RS0059.severity = warning # Do not add multiple public overloads with optional parameters
dotnet_diagnostic.RS0060.severity = warning # API with optional parameter(s) should have the most parameters amongst its public overloads
dotnet_diagnostic.RS0061.severity = warning # Constructor make noninheritable base class inheritable
64 changes: 64 additions & 0 deletions src/Cli/Microsoft.DotNet.FileBasedPrograms/ExternalHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable
using System;
using System.IO;

namespace Microsoft.DotNet.FileBasedPrograms;

/// <summary>
/// When targeting netstandard2.0, the user of the source package must "implement" certain methods by declaring members in this type.
/// </summary>
internal partial class ExternalHelpers
{
public static partial int CombineHashCodes(int value1, int value2);
public static partial string GetRelativePath(string relativeTo, string path);

public static partial bool IsPathFullyQualified(string path);

#if NET
public static partial int CombineHashCodes(int value1, int value2)
=> HashCode.Combine(value1, value2);

public static partial string GetRelativePath(string relativeTo, string path)
=> Path.GetRelativePath(relativeTo, path);

public static partial bool IsPathFullyQualified(string path)
=> Path.IsPathFullyQualified(path);

#elif FILE_BASED_PROGRAMS_SOURCE_PACKAGE_BUILD
// This path should only be used when we are verifying that the source package itself builds under netstandard2.0.
public static partial int CombineHashCodes(int value1, int value2)
=> throw new NotImplementedException();

public static partial string GetRelativePath(string relativeTo, string path)
=> throw new NotImplementedException();

public static partial bool IsPathFullyQualified(string path)
=> throw new NotImplementedException();

#endif
}

// https://github.com/dotnet/sdk/issues/51487: Remove usage of GracefulException from the source package
#if FILE_BASED_PROGRAMS_SOURCE_PACKAGE_GRACEFUL_EXCEPTION
internal class GracefulException : Exception
Copy link
Member

@tmat tmat Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove all the exception throwing? We already report diagnostics, right?
The calling code can convert diagnostics to an exception if needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be best to remove usage of this type from the source package. But, it will involve a decent chunk of refactoring.

{
public GracefulException()
{
}

public GracefulException(string? message) : base(message)
{
}

public GracefulException(string format, string arg) : this(string.Format(format, arg))
{
}

public GracefulException(string? message, Exception? innerException) : base(message, innerException)
{
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?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="CouldNotFindAnyProjectInDirectory" xml:space="preserve">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove these strings from the original resx to avoid duplication?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry, this should have been included in the original pure move commit.

Copy link
Member Author

@RikkiGibson RikkiGibson Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these are also used in non-file-based programs scenarios, such as CouldNotFindAnyProjectInDirectory, but perhaps changing those sites to use FileBasedProgramsResources isn't really a problem?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did 2 things to try and clean up this area:

  1. Introduced extensions for the CliStrings which were deleted, which redirect to FileBasedProgramsResources, to avoid some churn at use sites.
  2. Migrated the translated strings from the old CliStrings/CliCommandStrings xlf files, to the new FileBasedProgramsResources xlf files.

<value>Could not find any project in `{0}`.</value>
</data>
<data name="CouldNotFindProjectOrDirectory" xml:space="preserve">
<value>Could not find project or directory `{0}`.</value>
</data>
<data name="MoreThanOneProjectInDirectory" xml:space="preserve">
<value>Found more than one project in `{0}`. Specify which one to use.</value>
</data>
<data name="PropertyDirectiveInvalidName" xml:space="preserve">
<value>Invalid property name: {0}</value>
<comment>{0} is an inner exception message.</comment>
</data>
<data name="PropertyDirectiveMissingParts" xml:space="preserve">
<value>The property directive needs to have two parts separated by '=' like '#:property PropertyName=PropertyValue'.</value>
<comment>{Locked="#:property"}</comment>
</data>
<data name="StaticGraphRestoreNotSupported" xml:space="preserve">
<value>Static graph restore is not supported for file-based apps. Remove the '#:property'.</value>
<comment>{Locked="#:property"}</comment>
</data>
<data name="DirectiveError" xml:space="preserve">
<value>error</value>
<comment>Used when reporting directive errors like "file(location): error: message".</comment>
</data>
<data name="InvalidDirectiveName" xml:space="preserve">
<value>The directive should contain a name without special characters and an optional value separated by '{1}' like '#:{0} Name{1}Value'.</value>
<comment>{0} is the directive type like 'package' or 'sdk'. {1} is the expected separator like '@' or '='.</comment>
</data>
<data name="CannotConvertDirective" xml:space="preserve">
<value>Some directives cannot be converted. Run the file to see all compilation errors. Specify '--force' to convert anyway.</value>
<comment>{Locked="--force"}</comment>
</data>
<data name="DuplicateDirective" xml:space="preserve">
<value>Duplicate directives are not supported: {0}</value>
<comment>{0} is the directive type and name.</comment>
</data>
<data name="QuoteInDirective" xml:space="preserve">
<value>Directives currently cannot contain double quotes (").</value>
</data>
<data name="InvalidProjectDirective" xml:space="preserve">
<value>The '#:project' directive is invalid: {0}</value>
<comment>{0} is the inner error message.</comment>
</data>
<data name="MissingDirectiveName" xml:space="preserve">
<value>Missing name of '{0}'.</value>
<comment>{0} is the directive name like 'package' or 'sdk'.</comment>
</data>
<data name="UnrecognizedDirective" xml:space="preserve">
<value>Unrecognized directive '{0}'.</value>
<comment>{0} is the directive name like 'package' or 'sdk'.</comment>
</data>
</root>
Loading