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
2 changes: 1 addition & 1 deletion release-notes/11.0/preview/rc2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
40 changes: 40 additions & 0 deletions release-notes/11.0/preview/rc2/sdk.md
Original file line number Diff line number Diff line change
@@ -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<AssemblyCompanyAttribute>()?.Company;
var nameOption = new CommandLine::System.CommandLine.Option<string>("--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 <profile>` ([dotnet/sdk #56064](https://github.com/dotnet/sdk/pull/56064)).
19 changes: 19 additions & 0 deletions release-notes/11.0/samples/sdk/Program.cs
Comment thread
baronfel marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -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<AssemblyCompanyAttribute>()?.Company;
var nameOption = new CommandLine::System.CommandLine.Option<string>("--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}");
5 changes: 5 additions & 0 deletions release-notes/11.0/samples/sdk/README.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions release-notes/11.0/samples/sdk/launch-profile/Program.cs
Original file line number Diff line number Diff line change
@@ -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]}");
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"AssemblyName": {
"commandName": "Project",
"commandLineArgs": "$(AssemblyName)"
}
}
}
Loading