diff --git a/release-notes/11.0/preview/rc2/README.md b/release-notes/11.0/preview/rc2/README.md index a889ba0678..8ba2b84272 100644 --- a/release-notes/11.0/preview/rc2/README.md +++ b/release-notes/11.0/preview/rc2/README.md @@ -4,7 +4,7 @@ Browse the .NET 11 RC 2 release notes by component: - Libraries - Runtime -- SDK +- [SDK](./sdk.md) - [MSBuild](./msbuild.md) - [NuGet](./nuget.md) diff --git a/release-notes/11.0/preview/rc2/sdk.md b/release-notes/11.0/preview/rc2/sdk.md new file mode 100644 index 0000000000..1ec9f00674 --- /dev/null +++ b/release-notes/11.0/preview/rc2/sdk.md @@ -0,0 +1,40 @@ +# SDK in .NET 11 RC 2 - Release Notes + +.NET 11 RC 2 improves file-based program configuration and launch-profile arguments: + +- [Quoted file-level directive values](#quoted-file-level-directive-values) +- [MSBuild properties in launch-profile arguments](#msbuild-properties-in-launch-profile-arguments) + +## Quoted file-level directive values + +File-based programs can use quoted values containing spaces in `#:property` directives. The `#:package`, `#:project`, and `#:ref` directives also accept trailing `Name=Value` tokens for MSBuild item metadata. This example uses the `Aliases` metadata on a package directive and references the package through the resulting C# extern alias ([dotnet/sdk #55960](https://github.com/dotnet/sdk/pull/55960)). + +```csharp +#:property Company="RC2 Validation Team" +#:property AssemblyTitle="RC2 Directive Validation" +#:package System.CommandLine@2.0.1 Aliases=CommandLine + +extern alias CommandLine; +using System.Reflection; + +string? company = Assembly.GetExecutingAssembly() + .GetCustomAttribute()?.Company; +var nameOption = new CommandLine::System.CommandLine.Option("--name"); +var command = new CommandLine::System.CommandLine.RootCommand(); +command.Options.Add(nameOption); +string? name = command.Parse(args).GetValue(nameOption); +if (company != "RC2 Validation Team" || name != "RC2") +{ + throw new Exception($"Unexpected metadata or argument: {company}, {name}."); +} + +Console.WriteLine($"Company: {company}; name: {name}"); +``` + +Run the file with `dotnet run Program.cs -- --name RC2`. The quoted value becomes the generated assembly's `Company` metadata, and `System.CommandLine` parses the supplied option through the `CommandLine` alias. + +See the [file-based apps documentation](https://learn.microsoft.com/dotnet/core/sdk/file-based-apps) for supported directives and the broader workflow. + +## MSBuild properties in launch-profile arguments + +`dotnet run` now expands MSBuild properties in a launch profile's `commandLineArgs` using the evaluated project. For example, a profile argument such as `--name $(AssemblyName)` receives the project's assembly name when you run `dotnet run --launch-profile ` ([dotnet/sdk #56064](https://github.com/dotnet/sdk/pull/56064)). diff --git a/release-notes/11.0/samples/sdk/Program.cs b/release-notes/11.0/samples/sdk/Program.cs new file mode 100644 index 0000000000..f3ff566f16 --- /dev/null +++ b/release-notes/11.0/samples/sdk/Program.cs @@ -0,0 +1,19 @@ +#:property Company="RC2 Validation Team" +#:property AssemblyTitle="RC2 Directive Validation" +#:package System.CommandLine@2.0.1 Aliases=CommandLine + +extern alias CommandLine; +using System.Reflection; + +string? company = Assembly.GetExecutingAssembly() + .GetCustomAttribute()?.Company; +var nameOption = new CommandLine::System.CommandLine.Option("--name"); +var command = new CommandLine::System.CommandLine.RootCommand(); +command.Options.Add(nameOption); +string? name = command.Parse(args).GetValue(nameOption); +if (company != "RC2 Validation Team" || name != "RC2") +{ + throw new Exception($"Unexpected metadata or argument: {company}, {name}."); +} + +Console.WriteLine($"Company: {company}; name: {name}"); diff --git a/release-notes/11.0/samples/sdk/README.md b/release-notes/11.0/samples/sdk/README.md new file mode 100644 index 0000000000..0c96413c81 --- /dev/null +++ b/release-notes/11.0/samples/sdk/README.md @@ -0,0 +1,5 @@ +# SDK release-note validation + +Run `dotnet run Program.cs -- --name RC2` from this directory with SDK `11.0.100-rc.2.26475.137`. The file-based app checks that a quoted file-level property becomes generated assembly metadata and uses `System.CommandLine` through a C# extern alias supplied by trailing `Aliases=CommandLine` package metadata. + +To verify MSBuild property expansion in file-based launch-profile arguments, run `dotnet run --file launch-profile/Program.cs --launch-profile AssemblyName` from this directory. The adjacent `Program.run.json` defines the profile, and the file-based program declares `AssemblyName`; it exits with an error if the property is not expanded. diff --git a/release-notes/11.0/samples/sdk/launch-profile/Program.cs b/release-notes/11.0/samples/sdk/launch-profile/Program.cs new file mode 100644 index 0000000000..5d6ad97fc3 --- /dev/null +++ b/release-notes/11.0/samples/sdk/launch-profile/Program.cs @@ -0,0 +1,8 @@ +#:property AssemblyName=LaunchProfileExpansion + +if (args.Length != 1 || args[0] != "LaunchProfileExpansion") +{ + throw new Exception($"Expected expanded AssemblyName argument; got '{string.Join(' ', args)}'."); +} + +Console.WriteLine($"Expanded launch-profile argument: {args[0]}"); diff --git a/release-notes/11.0/samples/sdk/launch-profile/Program.run.json b/release-notes/11.0/samples/sdk/launch-profile/Program.run.json new file mode 100644 index 0000000000..a4a0172367 --- /dev/null +++ b/release-notes/11.0/samples/sdk/launch-profile/Program.run.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "AssemblyName": { + "commandName": "Project", + "commandLineArgs": "$(AssemblyName)" + } + } +}