Skip to content

Commit dc8eef4

Browse files
authored
Merge pull request #2229 from nguerrera/fix-clean-without-assets-file
Fix regression in clean when no assets file is present
2 parents 3c8b1f9 + 1978024 commit dc8eef4

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

build/build.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ function InitializeDotNetCli {
9292
$env:DOTNET_INSTALL_DIR = $env:DotNetCoreSdkDir
9393
}
9494

95+
# Save MSBuild crash files info to log directory so that they are captured as build artifacts
96+
$env:MSBUILDDEBUGPATH=$LogDir
97+
9598
# Use dotnet installation specified in DOTNET_INSTALL_DIR if it contains the required SDK version,
9699
# otherwise install the dotnet CLI and SDK to repo local .dotnet directory to avoid potential permission issues.
97100
if (($env:DOTNET_INSTALL_DIR -ne $null) -and (Test-Path(Join-Path $env:DOTNET_INSTALL_DIR "sdk\$($GlobalJson.sdk.version)"))) {

build/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ function InitializeDotNetCli {
167167
export DOTNET_INSTALL_DIR="$DotNetCoreSdkDir"
168168
fi
169169

170+
# Save MSBuild crash files info to log directory so that they are captured as build artifacts
171+
export MSBUILDDEBUGPATH="$log_dir"
172+
170173
ReadJson "$global_json_file" "version"
171174
local dotnet_sdk_version="$readjsonvalue"
172175
local dotnet_root=""

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ Copyright (c) .NET Foundation. All rights reserved.
9292

9393
<PropertyGroup>
9494
<CoreCleanDependsOn>
95-
SuppressAssetsLogMessages;
95+
_SdkBeforeClean
9696
$(CoreCleanDependsOn)
9797
</CoreCleanDependsOn>
9898
</PropertyGroup>
9999

100100
<PropertyGroup>
101101
<RebuildDependsOn>
102-
UnsuppressAssetsLogMessages;
102+
_SdkBeforeRebuild;
103103
$(RebuildDependsOn)
104104
</RebuildDependsOn>
105105
</PropertyGroup>
@@ -200,29 +200,16 @@ Copyright (c) .NET Foundation. All rights reserved.
200200
</ItemGroup>
201201
</Target>
202202

203-
<!--
204-
============================================================
205-
SuppressAssetsLogMessages
206-
207-
Suppresses log messages from an existing project assets file.
208-
============================================================
209-
-->
210-
<Target Name="SuppressAssetsLogMessages" Condition="'$(UnsuppressAssetsLogMessages)' != 'true'">
211-
<PropertyGroup>
203+
<Target Name="_SdkBeforeClean">
204+
<PropertyGroup Condition="'$(_CleaningWithoutRebuilding)' == ''">
205+
<_CleaningWithoutRebuilding>true</_CleaningWithoutRebuilding>
212206
<EmitAssetsLogMessages>false</EmitAssetsLogMessages>
213207
</PropertyGroup>
214208
</Target>
215209

216-
<!--
217-
============================================================
218-
UnsuppressAssetsLogMessages
219-
220-
Unsuppresses log messages from an existing project assets file.
221-
============================================================
222-
-->
223-
<Target Name="UnsuppressAssetsLogMessages">
210+
<Target Name="_SdkBeforeRebuild">
224211
<PropertyGroup>
225-
<UnsuppressAssetsLogMessages>true</UnsuppressAssetsLogMessages>
212+
<_CleaningWithoutRebuilding>false</_CleaningWithoutRebuilding>
226213
</PropertyGroup>
227214
</Target>
228215

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.PackageDependencyResolution.targets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ Copyright (c) .NET Foundation. All rights reserved.
126126
</ResolvePackageDependenciesForBuildDependsOn>
127127
</PropertyGroup>
128128
<Target Name="ResolvePackageDependenciesForBuild"
129-
Condition=" '$(DesignTimeBuild)' != 'true' Or Exists('$(ProjectAssetsFile)')"
129+
Condition=" ('$(DesignTimeBuild)' != 'true' and '$(_CleaningWithoutRebuilding)' != 'true')
130+
Or Exists('$(ProjectAssetsFile)')"
130131
BeforeTargets="AssignProjectConfiguration"
131132
DependsOnTargets="$(ResolvePackageDependenciesForBuildDependsOn)" />
132133

src/Tests/Microsoft.NET.Clean.Tests/GivenThatWeWantToCleanAProject.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,41 @@ public void It_cleans_without_logging_assets_message()
5353
.And
5454
.NotHaveStdOutContaining("warning");
5555
}
56+
57+
[Fact]
58+
public void It_cleans_without_assets_file_present()
59+
{
60+
var testAsset = _testAssetsManager
61+
.CopyTestAsset("HelloWorld")
62+
.WithSource();
63+
64+
var assetsFilePath = Path.Combine(testAsset.TestRoot, "obj", "project.assets.json");
65+
File.Exists(assetsFilePath).Should().BeFalse();
66+
67+
var cleanCommand = new CleanCommand(Log, testAsset.TestRoot);
68+
69+
cleanCommand
70+
.Execute()
71+
.Should()
72+
.Pass();
73+
}
74+
75+
// Related to https://github.com/dotnet/sdk/issues/2233
76+
// This test will fail if the naive fix for not reading assets file during clean is attempted
77+
[Fact]
78+
public void It_can_clean_and_build_without_using_rebuild()
79+
{
80+
var testAsset = _testAssetsManager
81+
.CopyTestAsset("HelloWorld")
82+
.WithSource()
83+
.Restore(Log);
84+
85+
var cleanAndBuildCommand = new MSBuildCommand(Log, "Clean;Build", testAsset.TestRoot);
86+
87+
cleanAndBuildCommand
88+
.Execute()
89+
.Should()
90+
.Pass();
91+
}
5692
}
5793
}

0 commit comments

Comments
 (0)