Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Set publishDir for file based apps #49514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 26, 2025
Merged

Conversation

chsienki
Copy link
Member

Fixes: #49387

@Copilot Copilot AI review requested due to automatic review settings June 20, 2025 18:34
@chsienki chsienki added the Area-run-file Items related to the "dotnet run <file>" effort label Jun 20, 2025
@chsienki
Copy link
Member Author

@dotnet/run-file for review please

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Updates the default publish directory for file-based apps and adds tests to verify the new behavior.

  • Adds a <PublishDir> MSBuild property to the virtual project template.
  • Updates existing publish tests to assert on the new artifacts/<ProjectName> layout.
  • Introduces new tests covering custom publish directory scenarios (default, CLI override, and property directive).

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
test/dotnet.Tests/CommandTests/Run/RunFileTests.cs Switches tests to use publishDir and adds new publish-dir tests
src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs Sets default <PublishDir>artifacts/$(MSBuildProjectName)</PublishDir> in generated project

@@ -536,6 +536,7 @@ public static void WriteProjectFile(
<PropertyGroup>
<IncludeProjectNameInArtifactsPaths>false</IncludeProjectNameInArtifactsPaths>
<ArtifactsPath>{EscapeValue(artifactsPath)}</ArtifactsPath>
<PublishDir>artifacts/$(MSBuildProjectName)</PublishDir>
Copy link
Member

@jjonescz jjonescz Jun 23, 2025

Choose a reason for hiding this comment

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

I assume this is relative to the "current csproj file", not "current working directory", right? So running dotnet publish ./subdir/app.cs would result in ./subdir/publish/artifacts/app/app.exe and not ./publish/artifacts/app/app.exe. Consider adding a test for that.

Copy link
Member

@DamianEdwards DamianEdwards Jun 23, 2025

Choose a reason for hiding this comment

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

From https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-reserved-and-well-known-properties?view=vs-2022:

The file name of the project file without the file name extension; for example, MyApp.

RE PublishDir, I believe it's relative to working directory, but I can't find docs for it.

Copy link
Member

Choose a reason for hiding this comment

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

Seems it maps to OutputPath:

}.ForwardAsOutputPath("PublishDir");

Copy link
Member

@DamianEdwards DamianEdwards Jun 23, 2025

Choose a reason for hiding this comment

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

OK, yes it's relative to the project directory:

Specifies the path to the output directory, relative to the project directory, for example, bin\Debug or bin\Debug$(Platform) in non-AnyCPU builds.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a test to confirm and cover behavior.

@chsienki chsienki merged commit a622859 into dotnet:main Jun 26, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-run-file Items related to the "dotnet run <file>" effort
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change default output path when publishing file-based apps
4 participants