diff --git a/src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs b/src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs index f86236b3a96d..83330e2fd99d 100644 --- a/src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs +++ b/src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs @@ -477,7 +477,8 @@ ProjectRootElement CreateProjectRootElement(ProjectCollection projectCollection) _directives, isVirtualProject: true, targetFilePath: EntryPointFileFullPath, - artifactsPath: GetArtifactsPath()); + artifactsPath: GetArtifactsPath(), + includeRuntimeConfigInformation: BuildTarget != "Publish"); var projectFileText = projectFileWriter.ToString(); using var reader = new StringReader(projectFileText); @@ -511,7 +512,8 @@ public static void WriteProjectFile( ImmutableArray directives, bool isVirtualProject, string? targetFilePath = null, - string? artifactsPath = null) + string? artifactsPath = null, + bool includeRuntimeConfigInformation = true) { int processedDirectives = 0; @@ -691,14 +693,17 @@ public static void WriteProjectFile( """); - var targetDirectory = Path.GetDirectoryName(targetFilePath) ?? ""; - writer.WriteLine($""" + if (includeRuntimeConfigInformation) + { + var targetDirectory = Path.GetDirectoryName(targetFilePath) ?? ""; + writer.WriteLine($""" """); + } foreach (var sdk in sdkDirectives) {