Skip to content

Commit f482547

Browse files
authored
Remove unsetting of NetCoreTargetingPackRoot to allow package pruning (#70)
Contributes to #61 Package pruning in .NET 10 requires `NetCoreTargetingPackRoot` to be set. Previously, we unset that property to isolate the build environment from machine configuration. To resolve the issue, we're removing our unsetting of this property so that package pruning can work as expected. The more officially supported way to instead enforce a consistent SDK version is via global.json. However, enforcing that is a bigger change that may break some workflows. As a result, we're going to ship this change in two pieces: this piece, which is non-breaking and unblocks .NET 10 SDK adoption. The global.json enforcement will come later in #69.
1 parent e6065e5 commit f482547

File tree

9 files changed

+50
-46
lines changed

9 files changed

+50
-46
lines changed

docs/Reproducible-MSBuild/Techniques/NetCoreTargetingPackRoot.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

docs/Reproducible-MSBuild/Techniques/toc.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
- [DisableImplicitNuGetFallbackFolder](./DisableImplicitNuGetFallbackFolder.md)
55
- [DisableImplicitLibraryPacksFolder](./DisableImplicitLibraryPacksFolder.md)
66
- [DOTNET_MULTILEVEL_LOOKUP](./DOTNET_MULTILEVEL_LOOKUP.md)
7-
- [NetCoreTargetingPackRoot](./NetCoreTargetingPackRoot.md)
87
- [NUGET_XMLDOC_MODE](./NUGET_XMLDOC_MODE.md)
98
- [TargetFrameworkRootPath](./TargetFrameworkRootPath.md)

src/DotNet.ReproducibleBuilds.Isolated/Sdk/Sdk.props

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@
3737
Text="Error, TargetFrameworkRootPath not initialized. If you're building for net462 or any other version of desktop NETFramework, please reference the 'Microsoft.NETFramework.ReferenceAssemblies' nuget package and run restore on the project to fix up your framework reference paths." />
3838
</Target>
3939

40-
<!--
41-
Disable msbuild's lookup of dotnetcore, dotnet5+ framework reference assemblies through default install
42-
locations. Instead, resolve from nuget feed.
43-
-->
44-
<PropertyGroup>
45-
<NetCoreTargetingPackRoot>[UNDEFINED]</NetCoreTargetingPackRoot>
46-
</PropertyGroup>
47-
4840
<!--
4941
Disable the extra implicit nuget package caches provided by dotnetsdk.
5042
-->
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using DotNet.ReproducibleBuilds.Tests.Shared;
2+
3+
using FluentAssertions;
4+
5+
using Microsoft.Build.Utilities.ProjectCreation;
6+
7+
namespace DotNet.ReproducibleBuilds.Isolated.Tests;
8+
9+
public class IsolatedProjectTests : TestBase
10+
{
11+
[Fact]
12+
public void ProjectCanRestore()
13+
{
14+
ProjectCreator.Templates
15+
.ReproducibleBuildsIsolatedProject(GetRandomFile(".csproj"), configureProject: project =>
16+
{
17+
project.Property("TargetFramework", GetCurrentTargetFrameworkMoniker());
18+
})
19+
.TryRestore(out bool result, out BuildOutput output);
20+
21+
output.Errors.Should().HaveCount(0);
22+
output.Warnings.Should().HaveCount(0);
23+
result.Should().BeTrue();
24+
}
25+
}

tests/DotNet.ReproducibleBuilds.Tests/ContinuousIntegrationTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void RespectsSetValue(bool? value, string expected)
1818
using EnvironmentVariableSuppressor hostSuppressor = new("TF_BUILD"); // Suppress our own CI provider variables (i.e. Azure DevOps)
1919

2020
ProjectCreator.Templates
21-
.ReproducibleBuildProject(GetRandomFile(".csproj"))
21+
.ReproducibleBuildsProject(GetRandomFile(".csproj"))
2222
.PropertyGroup()
2323
.Property(ContinuousIntegrationBuild, value?.ToLowerInvariant())
2424
.Project
@@ -34,14 +34,14 @@ public void RespectsGlobalProperties(Dictionary<string, string> envVars)
3434

3535
// If ContinuousIntegrationBuild is not set, it should be set from the CI provider property
3636
ProjectCreator.Templates
37-
.ReproducibleBuildProject(GetRandomFile(".csproj"))
37+
.ReproducibleBuildsProject(GetRandomFile(".csproj"))
3838
.ProjectWithGlobalProperties(envVars)
3939
.GetPropertyValue(ContinuousIntegrationBuild)
4040
.Should().Be(true.ToLowerInvariant());
4141

4242
// If ContinuousIntegrationBuild is set, it should take precedence over the CI provider variables
4343
ProjectCreator.Templates
44-
.ReproducibleBuildProject(GetRandomFile(".csproj"))
44+
.ReproducibleBuildsProject(GetRandomFile(".csproj"))
4545
.ProjectWithGlobalProperties(envVars.With(ContinuousIntegrationBuild, false.ToLowerInvariant()))
4646
.GetPropertyValue(ContinuousIntegrationBuild)
4747
.Should().Be(false.ToLowerInvariant(), "because explicitly setting `ContinuousIntegrationBuild` should always win.");

tests/DotNet.ReproducibleBuilds.Tests/MinimumVersionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void BelowMinimumVersionEmitsWarning(string msbuildVersion, bool success,
2020
};
2121

2222
ProjectCreator project = ProjectCreator.Templates
23-
.ReproducibleBuildProject(GetRandomFile(".csproj"));
23+
.ReproducibleBuildsProject(GetRandomFile(".csproj"));
2424

2525
if (suppress)
2626
{

tests/DotNet.ReproducibleBuilds.Tests/ProjectTemplates.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal static class ProjectTemplates
99
{
1010
private static readonly string ThisAssemblyDirectory = Path.GetDirectoryName(typeof(ProjectTemplates).Assembly.Location)!;
1111

12-
public static ProjectCreator ReproducibleBuildProject(this ProjectCreatorTemplates templates, FileInfo project)
12+
public static ProjectCreator ReproducibleBuildsProject(this ProjectCreatorTemplates templates, FileInfo project)
1313
{
1414
DirectoryInfo directory = project.Directory ?? throw new ArgumentException("Project's path does not appear to have a parent.", nameof(project));
1515

@@ -26,6 +26,6 @@ public static ProjectCreator ReproducibleBuildProject(this ProjectCreatorTemplat
2626
ProjectCollection projectCollection = new(); // Create a new collection for each project to ensure environment variables aren't shared between tests
2727

2828
return templates
29-
.SdkCsproj(path: project.FullName, targetFramework: "net9.0", projectCollection: projectCollection);
29+
.SdkCsproj(path: project.FullName, targetFramework: "net8.0", projectCollection: projectCollection);
3030
}
3131
}

tests/DotNet.ReproducibleBuilds.Tests/SourceLinkTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class SourceLinkTests : TestBase
1414
public void PublishRepositoryUrlIsSet(bool? publishRepositoryUrl, bool expected)
1515
{
1616
ProjectCreator.Templates
17-
.ReproducibleBuildProject(GetRandomFile(".csproj"))
17+
.ReproducibleBuildsProject(GetRandomFile(".csproj"))
1818
.PropertyGroup()
1919
.Property("PublishRepositoryUrl", publishRepositoryUrl.ToLowerInvariant())
2020
.Project
@@ -29,7 +29,7 @@ public void PublishRepositoryUrlIsSet(bool? publishRepositoryUrl, bool expected)
2929
public void DebugTypeIsSet(string? debugType, string expected)
3030
{
3131
ProjectCreator.Templates
32-
.ReproducibleBuildProject(GetRandomFile(".csproj"))
32+
.ReproducibleBuildsProject(GetRandomFile(".csproj"))
3333
.PropertyGroup()
3434
.Property("DebugType", debugType)
3535
.Project
@@ -44,7 +44,7 @@ public void DebugTypeIsSet(string? debugType, string expected)
4444
public void EmbedUntrackedSourcesIsSet(bool? embedUntrackedSources, bool expected)
4545
{
4646
ProjectCreator.Templates
47-
.ReproducibleBuildProject(GetRandomFile(".csproj"))
47+
.ReproducibleBuildsProject(GetRandomFile(".csproj"))
4848
.PropertyGroup()
4949
.Property("PublishRepositoryUrl", embedUntrackedSources.ToLowerInvariant())
5050
.Project
@@ -60,7 +60,7 @@ public void RepositoryBranchIsSet(Dictionary<string, string?> env, string expect
6060
using IDisposable ciSuppressors = env.Select(kvp => new EnvironmentVariableSuppressor(kvp.Key)).ToDisposable(); // Suppress the mock CI provider (just in case)
6161

6262
ProjectCreator project = ProjectCreator.Templates
63-
.ReproducibleBuildProject(GetRandomFile(".csproj"))
63+
.ReproducibleBuildsProject(GetRandomFile(".csproj"))
6464
.PropertyGroup()
6565
.Properties(env);
6666

tests/Shared/TestBase.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ public void Dispose()
1515
GC.SuppressFinalize(this);
1616
}
1717

18+
protected string GetCurrentTargetFrameworkMoniker()
19+
{
20+
#if NETFRAMEWORK
21+
return "net472";
22+
#elif NET8_0
23+
return "net8.0";
24+
#elif NET9_0
25+
return "net9.0";
26+
#elif NET10_0
27+
return "net10.0";
28+
#else
29+
throw new NotSupportedException("Unsupported target framework.");
30+
#endif
31+
}
32+
1833
protected virtual void Dispose(bool isDisposing)
1934
{
2035
TestRootPath.Refresh();

0 commit comments

Comments
 (0)