Skip to content

Commit

Permalink
Switch from artifacts to bin folder for new format, rename properties
Browse files Browse the repository at this point in the history
  • Loading branch information
dsplaisted committed Mar 23, 2023
1 parent caa24c4 commit aeb1caa
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 66 deletions.
18 changes: 9 additions & 9 deletions src/Tasks/Microsoft.NET.Build.Tasks/sdk/Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Copyright (c) .NET Foundation. All rights reserved.



<!-- We need to put the UseArtifactsOutput logic after the import of Directory.Build.props, but before the MSBuild Project Extensions .props import.
<!-- We need to put the UseStandardOutputPaths logic after the import of Directory.Build.props, but before the MSBuild Project Extensions .props import.
However, both of these things happen in Microsoft.Common.props with no opportunity to insert logic in between them.
So what we do here is duplicate the Directory.Build.props import logic from Microsoft.Common.props, and then set ImportDirectoryBuildProps to
Expand All @@ -57,15 +57,15 @@ Copyright (c) .NET Foundation. All rights reserved.
<ImportDirectoryBuildProps>false</ImportDirectoryBuildProps>
</PropertyGroup>

<!-- Set up base artifacts folders if UseArtifactsOutput is set -->
<PropertyGroup Condition="'$(UseArtifactsOutput)' == 'true'">
<UseArtifactsIntermediateOutput Condition="'$(UseArtifactsIntermediateOutput)' == ''">true</UseArtifactsIntermediateOutput>

<BaseArtifactsPath Condition="'$(BaseArtifactsPath)' == ''">artifacts\</BaseArtifactsPath>
<BaseArtifactsPath>$([MSBuild]::EnsureTrailingSlash($(BaseArtifactsPath)))</BaseArtifactsPath>
<!-- Set up base standard output folders if UseStandardOutputPaths is set -->
<PropertyGroup Condition="'$(UseStandardOutputPaths)' == 'true'">
<UseStandardIntermediateOutput Condition="'$(UseStandardIntermediateOutput)' == ''">true</UseStandardIntermediateOutput>

<BaseOutputPath Condition="'$(BaseOutputPath)' == ''">$(BaseArtifactsPath)bin\</BaseOutputPath>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' == ''">$(BaseArtifactsPath)intermediates\</BaseIntermediateOutputPath>
<BaseStandardOutputPath Condition="'$(BaseStandardOutputPath)' == ''">bin\</BaseStandardOutputPath>
<BaseStandardOutputPath>$([MSBuild]::EnsureTrailingSlash($(BaseStandardOutputPath)))</BaseStandardOutputPath>

<BaseOutputPath Condition="'$(BaseOutputPath)' == ''">$(BaseStandardOutputPath)build\</BaseOutputPath>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' == ''">$(BaseStandardOutputPath)obj\</BaseIntermediateOutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(MSBuildProjectFullPath)' == '$(ProjectToOverrideProjectExtensionsPath)'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,33 @@ Copyright (c) .NET Foundation. All rights reserved.
<AppendTargetFrameworkToOutputPath Condition="'$(AppendTargetFrameworkToOutputPath)' == ''">true</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

<!-- Set UseArtifactsOutput if not set and TargetFramework >= .NET 8 -->
<PropertyGroup Condition="'$(UseArtifactsOutput)' == '' and
<!-- Set UseStandardOutputPaths if not set and TargetFramework >= .NET 8 -->
<PropertyGroup Condition="'$(UseStandardOutputPaths)' == '' and
'$(TargetFrameworks)' == '' and
'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), 8.0))">
<UseArtifactsOutput>true</UseArtifactsOutput>
<UseStandardOutputPaths>true</UseStandardOutputPaths>
</PropertyGroup>

<!-- Set BaseOutputPath for artifacts format if it wasn't set in Sdk.props -->
<PropertyGroup Condition="'$(UseArtifactsOutput)' == 'true'">
<BaseArtifactsPath Condition="'$(BaseArtifactsPath)' == ''">artifacts\</BaseArtifactsPath>
<BaseArtifactsPath>$([MSBuild]::EnsureTrailingSlash($(BaseArtifactsPath)))</BaseArtifactsPath>
<!-- Set BaseOutputPath for standard output format if it wasn't set in Sdk.props -->
<PropertyGroup Condition="'$(UseStandardOutputPaths)' == 'true'">
<BaseStandardOutputPath Condition="'$(BaseStandardOutputPath)' == ''">bin\</BaseStandardOutputPath>
<BaseStandardOutputPath>$([MSBuild]::EnsureTrailingSlash($(BaseStandardOutputPath)))</BaseStandardOutputPath>

<BaseOutputPath Condition="'$(BaseOutputPath)' == ''">$(BaseArtifactsPath)bin\</BaseOutputPath>
<BaseOutputPath Condition="'$(BaseOutputPath)' == ''">$(BaseStandardOutputPath)build\</BaseOutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(UseArtifactsOutput)' != 'true'">
<PropertyGroup Condition="'$(UseStandardOutputPaths)' != 'true'">
<BaseOutputPath Condition="'$(BaseOutputPath)' == ''">bin\</BaseOutputPath>
<BaseOutputPath Condition="!HasTrailingSlash('$(BaseOutputPath)')">$(BaseOutputPath)\</BaseOutputPath>
<OutputPath Condition="'$(OutputPath)' == '' and '$(PlatformName)' == 'AnyCPU'">$(BaseOutputPath)$(Configuration)\</OutputPath>
<OutputPath Condition="'$(OutputPath)' == '' and '$(PlatformName)' != 'AnyCPU'">$(BaseOutputPath)$(PlatformName)\$(Configuration)\</OutputPath>
<OutputPath Condition="!HasTrailingSlash('$(OutputPath)')">$(OutputPath)\</OutputPath>
</PropertyGroup>

<!-- If "UseArtifactsOutput" wasn't set when the MSBuild project extensions .props files were imported, then use "obj" for the intermediate output path
instead of artifacts. To have the intermediate output path in the artifacts folder, "UseArtifactsOutput" should be set in Directory.Build.props-->
<PropertyGroup Condition="'$(UseArtifactsIntermediateOutput)' != 'true'">
<!-- If "UseStandardOutputPaths" wasn't set when the MSBuild project extensions .props files were imported, then use "obj" for the intermediate output path
instead of $(BaseStandardOutputPath)\obj. To have the intermediate output path in the standard output folder, "UseStandardOutputPaths" should be set in Directory.Build.props-->
<PropertyGroup Condition="'$(UseStandardIntermediateOutput)' != 'true'">
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' == ''">obj\</BaseIntermediateOutputPath>
<BaseIntermediateOutputPath Condition="!HasTrailingSlash('$(BaseIntermediateOutputPath)')">$(BaseIntermediateOutputPath)\</BaseIntermediateOutputPath>
<IntermediateOutputPath Condition=" $(IntermediateOutputPath) == '' and '$(PlatformName)' == 'AnyCPU' ">$(BaseIntermediateOutputPath)$(Configuration)\</IntermediateOutputPath>
Expand All @@ -61,43 +61,37 @@ Copyright (c) .NET Foundation. All rights reserved.

<!-- Set the package output path (for nuget pack target) now, before the TargetFramework is appended -->
<PropertyGroup Condition="'$(PackageOutputPath)' == ''">
<PackageOutputPath Condition="'$(UseArtifactsOutput)' != 'true'">$(OutputPath)</PackageOutputPath>
<PackageOutputPath Condition="'$(UseArtifactsOutput)' == 'true'">$(BaseArtifactsPath)\package\$(Configuration.ToLowerInvariant())\</PackageOutputPath>
<PackageOutputPath Condition="'$(UseStandardOutputPaths)' != 'true'">$(OutputPath)</PackageOutputPath>
<PackageOutputPath Condition="'$(UseStandardOutputPaths)' == 'true'">$(BaseStandardOutputPath)\package\$(Configuration.ToLowerInvariant())\</PackageOutputPath>
</PropertyGroup>

<!-- Exclude files from OutputPath and IntermediateOutputPath from default item globs. Use the value
of these properties before the TargetFramework is appended, so that if these values are specified
in the project file, the specified value will be used for the exclude. -->
<PropertyGroup Condition="'$(UseArtifactsOutput)' != 'true'">
<PropertyGroup Condition="'$(UseStandardOutputPaths)' != 'true'">
<DefaultItemExcludes>$(DefaultItemExcludes);$(OutputPath)/**</DefaultItemExcludes>
<DefaultItemExcludes>$(DefaultItemExcludes);$(IntermediateOutputPath)/**</DefaultItemExcludes>
</PropertyGroup>

<PropertyGroup Condition="'$(UseArtifactsOutput)' == 'true'">
<DefaultItemExcludes>$(DefaultItemExcludes);$(BaseArtifactsPath)/**</DefaultItemExcludes>

<!-- Exclude bin and obj folders even when using artifacts output format, so that when a project is changed
to use artifacts format (for example by retargeting to .NET 8, it doesn't suddenly pick up files from
bin and obj. -->
<DefaultItemExcludes>$(DefaultItemExcludes);bin/**</DefaultItemExcludes>
<DefaultItemExcludes>$(DefaultItemExcludes);obj/**</DefaultItemExcludes>
<PropertyGroup Condition="'$(UseStandardOutputPaths)' == 'true'">
<DefaultItemExcludes>$(DefaultItemExcludes);$(BaseStandardOutputPath)/**</DefaultItemExcludes>
</PropertyGroup>

<!--
Append $(TargetFramework) directory to output and intermediate paths to prevent bin clashes between
targets.
-->
<PropertyGroup Condition="'$(UseArtifactsOutput)' != 'true' and
<PropertyGroup Condition="'$(UseStandardOutputPaths)' != 'true' and
'$(AppendTargetFrameworkToOutputPath)' == 'true' and '$(TargetFramework)' != '' and '$(_UnsupportedTargetFrameworkError)' != 'true'">
<OutputPath>$(OutputPath)$(TargetFramework.ToLowerInvariant())\</OutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(UseArtifactsIntermediateOutput)' != 'true' and
<PropertyGroup Condition="'$(UseStandardIntermediateOutput)' != 'true' and
'$(AppendTargetFrameworkToOutputPath)' == 'true' and '$(TargetFramework)' != '' and '$(_UnsupportedTargetFrameworkError)' != 'true'">
<IntermediateOutputPath>$(IntermediateOutputPath)$(TargetFramework.ToLowerInvariant())\</IntermediateOutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(UseArtifactsOutput)' == 'true'">
<PropertyGroup Condition="'$(UseStandardOutputPaths)' == 'true'">
<_ArtifactPivots>$(Configuration.ToLowerInvariant())</_ArtifactPivots>

<!-- Per the design, we should include the TargetFramework in the pivots if TargetFrameworks is defined, or if TargetFramework is a global property.
Expand All @@ -121,11 +115,11 @@ Copyright (c) .NET Foundation. All rights reserved.

<!-- Publish path -->
<PublishDirName Condition="'$(PublishDirName)' == ''">publish</PublishDirName>
<PublishDir Condition="'$(PublishDir)' == ''">$(BaseArtifactsPath)$(PublishDirName)\$(_ArtifactPivots)\</PublishDir>
<PublishDir Condition="'$(PublishDir)' == ''">$(BaseStandardOutputPath)$(PublishDirName)\$(_ArtifactPivots)\</PublishDir>

</PropertyGroup>

<PropertyGroup Condition="'$(UseArtifactsOutput)' == 'true' and '$(UseArtifactsIntermediateOutput)' == 'true'">
<PropertyGroup Condition="'$(UseStandardOutputPaths)' == 'true' and '$(UseStandardIntermediateOutput)' == 'true'">
<IntermediateOutputPath Condition=" $(IntermediateOutputPath) == '' ">$(BaseIntermediateOutputPath)$(_ArtifactPivots)\</IntermediateOutputPath>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ Copyright (c) .NET Foundation. All rights reserved.
append a RID the user never mentioned in the path and do so even in the AnyCPU case.
-->
<PropertyGroup Condition="'$(AppendRuntimeIdentifierToOutputPath)' == 'true' and '$(RuntimeIdentifier)' != '' and '$(_UsingDefaultRuntimeIdentifier)' != 'true'">
<IntermediateOutputPath Condition="'$(UseArtifactsIntermediateOutput)' != 'true'">$(IntermediateOutputPath)$(RuntimeIdentifier)\</IntermediateOutputPath>
<OutputPath Condition="'$(UseArtifactsOutput)' != 'true'">$(OutputPath)$(RuntimeIdentifier)\</OutputPath>
<IntermediateOutputPath Condition="'$(UseStandardIntermediateOutput)' != 'true'">$(IntermediateOutputPath)$(RuntimeIdentifier)\</IntermediateOutputPath>
<OutputPath Condition="'$(UseStandardOutputPaths)' != 'true'">$(OutputPath)$(RuntimeIdentifier)\</OutputPath>
</PropertyGroup>

<UsingTask TaskName="Microsoft.NET.Build.Tasks.GetDefaultPlatformTargetForNetFramework"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ Copyright (c) .NET Foundation. All rights reserved.
</PropertyGroup>

<!-- Set PublishDir here, before Microsoft.Common.targets, to avoid a competing default there.
If using Artifacts output format, PublishDir is already set in Microsoft.NET.DefaultOutputPaths.targets -->
<PropertyGroup Condition="'$(UseArtifactsOutput)' != 'true'">
If using standard output path format, PublishDir is already set in Microsoft.NET.DefaultOutputPaths.targets -->
<PropertyGroup Condition="'$(UseStandardOutputPaths)' != 'true'">
<PublishDirName Condition="'$(PublishDirName)' == ''">publish</PublishDirName>
<!-- ensure the PublishDir is RID specific-->
<PublishDir Condition="'$(PublishDir)' == '' and
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/EndToEnd.Tests/GivenDotNetUsesMSBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void ItCanNewRestoreBuildRunCleanMSBuildProject()
.Should().Pass()
.And.HaveStdOutContaining("Hello, World!");

var binDirectory = new DirectoryInfo(projectDirectory).Sub("artifacts").Sub("bin");
var binDirectory = new DirectoryInfo(projectDirectory).Sub("bin").Sub("build");
binDirectory.Should().HaveFilesMatching("*.dll", SearchOption.AllDirectories);

new CleanCommand(Log, projectDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ public void It_publishes_package_satellites_correctly(bool crossTarget)
if (crossTarget)
{
// Let the GetOutputDirectory logic know that this project doesn't use the artifacts output format
testProject.UseArtifactsOutput = false;
testProject.UseStandardOutputPaths = false;
}

var outputDirectory = publishCommand.GetOutputDirectory(testProject.TargetFrameworks);
Expand All @@ -621,7 +621,7 @@ public void It_publishes_package_satellites_correctly(bool crossTarget)
[Theory]
[InlineData(true)]
[InlineData(false)]
public void It_uses_lowercase_form_of_the_target_framework_for_the_output_path(bool useArtifactsOutput)
public void It_uses_lowercase_form_of_the_target_framework_for_the_output_path(bool useStandardOutputPaths)
{
var testProject = new TestProject()
{
Expand All @@ -633,22 +633,22 @@ public void It_uses_lowercase_form_of_the_target_framework_for_the_output_path(b

string[] extraArgs = new[] { $"/p:TargetFramework={ToolsetInfo.CurrentTargetFramework.ToUpper()}" };

var testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name, identifier: useArtifactsOutput.ToString());
var testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name, identifier: useStandardOutputPaths.ToString());

var buildCommand = new BuildCommand(testAsset);

buildCommand
.WithEnvironmentVariable("UseArtifactsOutput", useArtifactsOutput.ToString())
.WithEnvironmentVariable("UseStandardOutputPaths", useStandardOutputPaths.ToString())
.Execute(extraArgs)
.Should()
.Pass();

if (useArtifactsOutput)
if (useStandardOutputPaths)
{
string outputFolder = Path.Combine(buildCommand.ProjectRootPath, "artifacts", "bin", $"debug_{ToolsetInfo.CurrentTargetFramework}");
string outputFolder = Path.Combine(buildCommand.ProjectRootPath, "bin", "build", $"debug_{ToolsetInfo.CurrentTargetFramework}");
new DirectoryInfo(outputFolder).Should().Exist();

string intermediateFolder = Path.Combine(buildCommand.ProjectRootPath, "artifacts", "intermediates", $"debug_{ToolsetInfo.CurrentTargetFramework}");
string intermediateFolder = Path.Combine(buildCommand.ProjectRootPath, "bin", "obj", $"debug_{ToolsetInfo.CurrentTargetFramework}");
new DirectoryInfo(intermediateFolder).Should().Exist();
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void It_builds_solution_successfully()

var buildCommand = new BuildCommand(testAsset, "x64SolutionBuild.sln");
buildCommand
.Execute("/p:ProduceReferenceAssembly=false", "/p:UseArtifactsOutput=false")
.Execute("/p:ProduceReferenceAssembly=false", "/p:UseStandardOutputPaths=false")
.Should()
.Pass();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void Build_Works_WithLibraryUsingHintPath()
reference.Name = "Reference";
reference.Add(new XElement(
"HintPath",
Path.Combine("..", "razorclasslibrary", "artifacts", "bin", "debug", "RazorClassLibrary.dll")));
Path.Combine("..", "razorclasslibrary", "bin", "build", "debug", "RazorClassLibrary.dll")));
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void Publish_Works_WithLibraryUsingHintPath()
reference.Name = "Reference";
reference.Add(new XElement(
"HintPath",
Path.Combine("..", "razorclasslibrary", "artifacts", "bin", "debug", "RazorClassLibrary.dll")));
Path.Combine("..", "razorclasslibrary", "bin", "build", "debug", "RazorClassLibrary.dll")));
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public List<string> GetValues()
DirectoryInfo GetValuesDirectory(string targetFramework = "", string configuration = "Debug")
{
// Use a consistent directory format to put the values text file in, so we don't have to worry about
// whether the project uses the artifacts output format or not
// whether the project uses the standard output path format or not

targetFramework = targetFramework ?? string.Empty;
configuration = configuration ?? string.Empty;
Expand Down
Loading

0 comments on commit aeb1caa

Please sign in to comment.