-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Ensure that a virtual project doesn't pick up BaseOutputPath/BaseIntermediateOutputPath from Directory.Build.props #51600
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
base: release/10.0.2xx
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1180,11 +1180,16 @@ public static void WriteProjectFile( | |
| // Note that ArtifactsPath needs to be specified before Sdk.props | ||
| // (usually it's recommended to specify it in Directory.Build.props | ||
| // but importing Sdk.props manually afterwards also works). | ||
| // | ||
| // An empty value is always given for BaseIntermediateOutputPath and BaseOutputPath, to ensure that | ||
| // the SDK targets will initialize them based on ArtifactsPath, and not use values for those paths coming in from Directory.Build.props. | ||
| writer.WriteLine($""" | ||
| <Project> | ||
|
|
||
| <PropertyGroup> | ||
| <IncludeProjectNameInArtifactsPaths>false</IncludeProjectNameInArtifactsPaths> | ||
| <BaseIntermediateOutputPath></BaseIntermediateOutputPath> | ||
| <BaseOutputPath></BaseOutputPath> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the user explicitly sets these via a |
||
| <ArtifactsPath>{EscapeValue(artifactsPath)}</ArtifactsPath> | ||
| <PublishDir>artifacts/$(MSBuildProjectName)</PublishDir> | ||
| <PackageOutputPath>artifacts/$(MSBuildProjectName)</PackageOutputPath> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -919,6 +919,39 @@ public void DefaultProps_DirectoryBuildProps() | |
| .And.HaveStdOutContaining("error CS0103"); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// 'BaseIntermediateOutputPath'/'BaseOutputPath' specified in Directory.Build.props should effectively be ignored. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| /// We want the standard logic for determining these from an 'ArtifactsPath' to always be used. | ||
| /// See also https://github.com/dotnet/sdk/blob/2b9fc02a265c735f2132e4e3626e94962e48bdf5/src/Tasks/Microsoft.NET.Build.Tasks/sdk/UseArtifactsOutputPath.props#L25. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not totally sold on this fix. It seems fine to allow users to override these properties. Is this basically a workaround for an IDE issue and should we fix the underlying issue instead (wrongly recognizing files as file-based apps)? Consider that this is reproable with project-based apps too - if I specify these properties and then have a artifacts-layout-enabled project somewhere, it would also not place artifacts to the artifacts folder. I guess changing that would be more breaking than scoping the change to just file-based apps though. |
||
| /// </summary> | ||
| [Fact] | ||
| public void BaseOutputPathProps_FromDirectoryBuildProps_NotUsed() | ||
| { | ||
| var testInstance = _testAssetsManager.CreateTestDirectory(); | ||
| File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), """ | ||
| Console.WriteLine("Hi"); | ||
| """); | ||
|
|
||
| var dbPropsObjPath = Path.Join(testInstance.Path, "MyOutput", "obj"); | ||
| var dbPropsBinPath = Path.Join(testInstance.Path, "MyOutput", "bin"); | ||
| File.WriteAllText(Path.Join(testInstance.Path, "Directory.Build.props"), $""" | ||
| <Project> | ||
| <PropertyGroup> | ||
| <BaseIntermediateOutputPath>{dbPropsObjPath}</BaseIntermediateOutputPath> | ||
| <BaseOutputPath>{dbPropsBinPath}</BaseOutputPath> | ||
| </PropertyGroup> | ||
| </Project> | ||
| """); | ||
|
|
||
| new DotnetCommand(Log, "run", "Program.cs") | ||
| .WithWorkingDirectory(testInstance.Path) | ||
| .Execute() | ||
| .Should().Pass(); | ||
|
|
||
| Assert.False(Directory.Exists(dbPropsObjPath)); | ||
| Assert.False(Directory.Exists(dbPropsBinPath)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Overriding default (implicit) properties of file-based apps from custom SDKs. | ||
| /// </summary> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this won't work (and the failing test seems to agree with me). Implicit build files are imported through SDKs below (see where we emit
<Import) so that will overwrite any values here.For properties that cannot be overwritten, see the block where we write
<RestoreUseStaticGraphEvaluation>false</RestoreUseStaticGraphEvaluation>for example.