Skip to content

Commit fdf6886

Browse files
authored
[automated] Merge branch 'release/10.0.2xx' => 'main' (#52149)
2 parents b300744 + 091259e commit fdf6886

File tree

231 files changed

+5509
-3976
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

231 files changed

+5509
-3976
lines changed

documentation/general/dotnet-run-file.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Additionally, the implicit project file has the following customizations:
3232

3333
- `PublishAot` is set to `true`, see [`dotnet publish file.cs`](#other-commands) for more details.
3434

35+
- `PackAsTool` is set to `true`, see [`dotnet pack file.cs`](#other-commands) for more details.
36+
3537
- `UserSecretsId` is set to a hash of the entry point file path.
3638

3739
- [File-level directives](#directives-for-project-metadata) are applied.
@@ -102,8 +104,14 @@ and working directory is not changed (e.g., `cd /x/ && dotnet run /y/file.cs` ru
102104
If a dash (`-`) is given instead of the target path (i.e., `dotnet run -`), the C# file to be executed is read from the standard input.
103105
In this case, the current working directory is not used to search for other files (launch profiles, other sources in case of multi-file apps);
104106
the compilation consists solely of the single file read from the standard input.
107+
However, the current working directory is still used as the working directory for building and executing the program.
108+
To reference projects relative to the current working directory (instead of relative to the temporary directory the file is isolated in),
109+
you can use something like `#:project $(MSBuildStartupDirectory)/relative/path`.
105110

106-
`dotnet path.cs` is a shortcut for `dotnet run --file path.cs` provided that `path.cs` is a valid [target path](#target-path) (`dotnet -` is currently not supported).
111+
`dotnet path.cs` is a shortcut for `dotnet run --file path.cs` provided that `path.cs` is a valid [target path](#target-path) (`dotnet -` is currently not supported)
112+
and it is not a DLL path, built-in command, or a NuGet tool (e.g., `dotnet watch` invokes the `dotnet-watch` tool
113+
even if a valid `watch` file-based app exists in the current directory;
114+
one can use `dotnet ./watch` to run the file-based app).
107115

108116
### Other commands
109117

@@ -112,6 +120,8 @@ Commands `dotnet restore file.cs` and `dotnet build file.cs` are needed for IDE
112120
Commands `dotnet publish file.cs` and `dotnet pack file.cs` are also supported for file-based programs.
113121
Note that file-based apps have implicitly set `PublishAot=true`, so publishing uses Native AOT (and building reports AOT warnings).
114122
To opt out, use `#:property PublishAot=false` directive in your `.cs` file.
123+
Additionally, file-based apps have implicitly set `PackAsTool=true` because file-based apps are usually tools;
124+
again, you can opt out via `#:property PackAsTool=false`.
115125

116126
Command `dotnet clean file.cs` can be used to clean build artifacts of the file-based program.
117127

src/BuiltInTools/HotReloadClient/DefaultHotReloadClient.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,15 @@ async Task<ImmutableArray<string>> ConnectAsync()
7777
// When the client connects, the first payload it sends is the initialization payload which includes the apply capabilities.
7878

7979
var capabilities = (await ClientInitializationResponse.ReadAsync(_pipe, cancellationToken)).Capabilities;
80-
Logger.Log(LogEvents.Capabilities, capabilities);
80+
81+
var result = AddImplicitCapabilities(capabilities.Split(' '));
82+
83+
Logger.Log(LogEvents.Capabilities, string.Join(" ", result));
8184

8285
// fire and forget:
8386
_ = ListenForResponsesAsync(cancellationToken);
8487

85-
return [.. capabilities.Split(' ')];
88+
return result;
8689
}
8790
catch (Exception e) when (e is not OperationCanceledException)
8891
{

src/BuiltInTools/HotReloadClient/HotReloadClient.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ internal abstract class HotReloadClient(ILogger logger, ILogger agentLogger) : I
4141
internal Task PendingUpdates
4242
=> _pendingUpdates;
4343

44+
/// <summary>
45+
/// .NET Framework runtime does not support adding MethodImpl entries, therefore the capability is not in the baseline capability set.
46+
/// All other runtimes (.NET and Mono) support it and rather than servicing all of them we include the capability here.
47+
/// </summary>
48+
protected static ImmutableArray<string> AddImplicitCapabilities(IEnumerable<string> capabilities)
49+
=> [.. capabilities, "AddExplicitInterfaceImplementation"];
50+
4451
public abstract void ConfigureLaunchEnvironment(IDictionary<string, string> environmentBuilder);
4552

4653
/// <summary>

src/BuiltInTools/HotReloadClient/Web/WebAssemblyHotReloadClient.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,30 @@ internal sealed class WebAssemblyHotReloadClient(
4141

4242
private static ImmutableArray<string> GetUpdateCapabilities(ILogger logger, ImmutableArray<string> projectHotReloadCapabilities, Version projectTargetFrameworkVersion)
4343
{
44-
var capabilities = projectHotReloadCapabilities;
45-
46-
if (capabilities.IsEmpty)
47-
{
48-
logger.LogDebug("Using capabilities based on project target framework version: '{Version}'.", projectTargetFrameworkVersion);
49-
50-
capabilities = projectTargetFrameworkVersion.Major switch
44+
var capabilities = projectHotReloadCapabilities.IsEmpty
45+
? projectTargetFrameworkVersion.Major switch
5146
{
5247
9 => s_defaultCapabilities90,
5348
8 => s_defaultCapabilities80,
5449
7 => s_defaultCapabilities70,
5550
6 => s_defaultCapabilities60,
5651
_ => [],
57-
};
52+
}
53+
: projectHotReloadCapabilities;
54+
55+
if (capabilities is not [])
56+
{
57+
capabilities = AddImplicitCapabilities(capabilities);
58+
}
59+
60+
var capabilitiesStr = string.Join(", ", capabilities);
61+
if (projectHotReloadCapabilities.IsEmpty)
62+
{
63+
logger.LogDebug("Project specifies capabilities: {Capabilities}.", capabilitiesStr);
5864
}
5965
else
6066
{
61-
logger.LogDebug("Project specifies capabilities: '{Capabilities}'", string.Join(" ", capabilities));
67+
logger.LogDebug("Using capabilities based on project target framework version: '{Version}': {Capabilities}.", projectTargetFrameworkVersion, capabilitiesStr);
6268
}
6369

6470
return capabilities;

src/BuiltInTools/Watch/Process/LaunchSettingsProfile.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal sealed class LaunchSettingsProfile
2525

2626
internal static LaunchSettingsProfile? ReadLaunchProfile(string projectPath, string? launchProfileName, ILogger logger)
2727
{
28-
var launchSettingsPath = LaunchSettingsLocator.TryFindLaunchSettings(projectPath, launchProfileName, (message, isError) =>
28+
var launchSettingsPath = LaunchSettings.TryFindLaunchSettingsFile(projectPath, launchProfileName, (message, isError) =>
2929
{
3030
if (isError)
3131
{
@@ -94,11 +94,16 @@ internal sealed class LaunchSettingsProfile
9494
return null;
9595
}
9696

97-
var defaultProfileKey = launchSettings.Profiles.FirstOrDefault(entry => entry.Value.CommandName == "Project").Key;
97+
// Look for the first profile with a supported command name
98+
// Note: These must match the command names supported by LaunchSettingsManager in src/Cli/dotnet/Commands/Run/LaunchSettings/
99+
var supportedCommandNames = new[] { "Project", "Executable" };
100+
var defaultProfileKey = launchSettings.Profiles.FirstOrDefault(entry =>
101+
entry.Value.CommandName != null && supportedCommandNames.Contains(entry.Value.CommandName, StringComparer.Ordinal)).Key;
98102

99103
if (defaultProfileKey is null)
100104
{
101-
logger.LogDebug("Unable to find 'Project' command in the default launch profile.");
105+
logger.LogDebug("Unable to find a supported command name in the default launch profile. Supported types: {SupportedTypes}",
106+
string.Join(", ", supportedCommandNames));
102107
return null;
103108
}
104109

src/Cli/Microsoft.DotNet.Cli.CommandLine/ForwardedOptionExtensions.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,16 @@ public Option<IEnumerable<string>> ForwardAsManyArgumentsEachPrefixedByOption(st
177177
/// <summary>
178178
/// Calls the forwarding functions for all options that have declared a forwarding function (via <see cref="ForwardedOptionExtensions"/>'s extension members) in the provided <see cref="ParseResult"/>.
179179
/// </summary>
180-
/// <param name="parseResult"></param>
181180
/// <param name="command">If not provided, uses the <see cref="ParseResult.CommandResult" />'s <see cref="CommandResult.Command"/>.</param>
182-
/// <returns></returns>
183-
public IEnumerable<string> OptionValuesToBeForwarded(Command? command = null) =>
184-
(command ?? parseResult.CommandResult.Command)
185-
.Options
181+
public IEnumerable<string> OptionValuesToBeForwarded(Command? command = null)
182+
=> parseResult.OptionValuesToBeForwarded((command ?? parseResult.CommandResult.Command).Options);
183+
184+
/// <summary>
185+
/// Calls the forwarding functions for all options that have declared a forwarding function (via <see cref="ForwardedOptionExtensions"/>'s extension members) in the provided <see cref="ParseResult"/>.
186+
/// </summary>
187+
/// <param name="command">If not provided, uses the <see cref="ParseResult.CommandResult" />'s <see cref="CommandResult.Command"/>.</param>
188+
public IEnumerable<string> OptionValuesToBeForwarded(IEnumerable<Option> options)
189+
=> options
186190
.Select(o => o.ForwardingFunction)
187191
.SelectMany(f => f is not null ? f(parseResult) : []);
188192

@@ -191,9 +195,6 @@ public IEnumerable<string> OptionValuesToBeForwarded(Command? command = null) =>
191195
/// invokes its forwarding function (if any) and returns the result. If no option with that name is found, or if the option
192196
/// has no forwarding function, returns an empty enumeration.
193197
/// </summary>
194-
/// <param name="command"></param>
195-
/// <param name="alias"></param>
196-
/// <returns></returns>
197198
public IEnumerable<string> ForwardedOptionValues(Command command, string alias)
198199
{
199200
var func = command.Options?

src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildArgs.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,4 +382,12 @@ public void ApplyPropertiesToRestore()
382382
RestoreGlobalProperties = new(newdict);
383383
}
384384
}
385+
386+
internal string[]? GetResolvedTargets()
387+
=> this switch
388+
{
389+
{ RequestedTargets: null or { Length: 0 } } => GetTargetResult,
390+
{ GetTargetResult: null or { Length: 0 } } => RequestedTargets,
391+
_ => [.. RequestedTargets.Union(GetTargetResult, StringComparer.OrdinalIgnoreCase)]
392+
};
385393
}

src/Cli/Microsoft.TemplateEngine.Cli/Microsoft.TemplateEngine.Cli.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
</ItemGroup>
2121

2222
<ItemGroup>
23-
<ProjectReference Include="../Microsoft.DotNet.Cli.CommandLine/Microsoft.DotNet.Cli.CommandLine.csproj" GlobalPropertiesToRemove="PublishDir" />
24-
<ProjectReference Include="../Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj" GlobalPropertiesToRemove="PublishDir" />
25-
<ProjectReference Include="../Microsoft.DotNet.Configurer/Microsoft.DotNet.Configurer.csproj" GlobalPropertiesToRemove="PublishDir" />
23+
<ProjectReference Include="..\Microsoft.DotNet.Cli.CommandLine\Microsoft.DotNet.Cli.CommandLine.csproj" GlobalPropertiesToRemove="PublishDir" />
24+
<ProjectReference Include="..\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" GlobalPropertiesToRemove="PublishDir" />
25+
<ProjectReference Include="..\Microsoft.DotNet.Configurer\Microsoft.DotNet.Configurer.csproj" GlobalPropertiesToRemove="PublishDir" />
26+
<ProjectReference Include="..\..\Microsoft.DotNet.ProjectTools\Microsoft.DotNet.ProjectTools.csproj" />
2627
</ItemGroup>
2728

2829
<ItemGroup>

src/Cli/Microsoft.TemplateEngine.Cli/TelemetryHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using Microsoft.DotNet.Cli.Utils;
4+
using Microsoft.DotNet.Utilities;
55
using Microsoft.TemplateEngine.Abstractions;
66
using Microsoft.TemplateEngine.Utils;
77

src/Cli/Microsoft.TemplateEngine.Cli/TemplateInvoker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text.RegularExpressions;
55
using Microsoft.DotNet.Cli.Utils;
66
using Microsoft.DotNet.Cli.Utils.Extensions;
7+
using Microsoft.DotNet.Utilities;
78
using Microsoft.TemplateEngine.Abstractions;
89
using Microsoft.TemplateEngine.Abstractions.TemplatePackage;
910
using Microsoft.TemplateEngine.Cli.Commands;

0 commit comments

Comments
 (0)