Skip to content
Merged
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
13 changes: 9 additions & 4 deletions src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,8 @@ ProjectRootElement CreateProjectRootElement(ProjectCollection projectCollection)
_directives,
isVirtualProject: true,
targetFilePath: EntryPointFileFullPath,
artifactsPath: GetArtifactsPath());
artifactsPath: GetArtifactsPath(),
includeRuntimeConfigInformation: BuildTarget != "Publish");
Copy link

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

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

Use a case-insensitive comparison when checking BuildTarget to avoid unexpected mismatches. For example: !string.Equals(BuildTarget, "Publish", StringComparison.OrdinalIgnoreCase).

Suggested change
includeRuntimeConfigInformation: BuildTarget != "Publish");
includeRuntimeConfigInformation: !string.Equals(BuildTarget, "Publish", StringComparison.OrdinalIgnoreCase));

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

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

[nitpick] Extract the literal "Publish" into a named constant or enum to eliminate a magic string and improve maintainability.

Suggested change
includeRuntimeConfigInformation: BuildTarget != "Publish");
includeRuntimeConfigInformation: BuildTarget != BuildTargets.Publish);

Copilot uses AI. Check for mistakes.
var projectFileText = projectFileWriter.ToString();

using var reader = new StringReader(projectFileText);
Expand Down Expand Up @@ -511,7 +512,8 @@ public static void WriteProjectFile(
ImmutableArray<CSharpDirective> directives,
bool isVirtualProject,
string? targetFilePath = null,
string? artifactsPath = null)
string? artifactsPath = null,
bool includeRuntimeConfigInformation = true)
{
int processedDirectives = 0;

Expand Down Expand Up @@ -691,14 +693,17 @@ public static void WriteProjectFile(

""");

var targetDirectory = Path.GetDirectoryName(targetFilePath) ?? "";
writer.WriteLine($"""
if (includeRuntimeConfigInformation)
Copy link

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

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

Add unit tests covering both paths of includeRuntimeConfigInformation (true and false) to verify the runtime config <ItemGroup> is correctly included or omitted. Use the Fact Skip parameter to reference issue #49368.

Copilot generated this review using guidance from repository custom instructions.
{
var targetDirectory = Path.GetDirectoryName(targetFilePath) ?? "";
writer.WriteLine($"""
<ItemGroup>
<RuntimeHostConfigurationOption Include="EntryPointFilePath" Value="{EscapeValue(targetFilePath)}" />
<RuntimeHostConfigurationOption Include="EntryPointFileDirectoryPath" Value="{EscapeValue(targetDirectory)}" />
</ItemGroup>

""");
}

foreach (var sdk in sdkDirectives)
{
Expand Down
Loading