Skip to content

Commit c1faabb

Browse files
authored
Add setting to opt-into ignoring the .NET SDK patch version (#105)
1 parent 147bc0b commit c1faabb

File tree

7 files changed

+27
-2
lines changed

7 files changed

+27
-2
lines changed

Directory.Packages.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929
<PackageVersion Include="Microsoft.VisualStudio.Services.BlobStore.Client" Version="$(ArtifactsPackageVersion)" />
3030
<PackageVersion Include="Microsoft.VisualStudio.Services.BlobStore.Client.Cache" Version="$(ArtifactsPackageVersion)" />
3131
<PackageVersion Include="Microsoft.VisualStudio.Services.PipelineCache.WebApi" Version="$(ArtifactsPackageVersion)" />
32+
<PackageVersion Include="morelinq" Version="3.4.2" />
3233
<PackageVersion Include="MSTest" Version="3.5.0" />
3334
<!--
3435
An indirect dependency of BXL (Minimatch) depends on a very old and non-existing version of NETStandard.Library (>= 1.0.0-rc2-23910).
3536
This forces a good version of NETStandard.Library to mitigate.
3637
-->
3738
<PackageVersion Include="NETStandard.Library" Version="2.0.3"/>
38-
<PackageVersion Include="morelinq" Version="3.4.2" />
39+
<PackageVersion Include="NuGet.Versioning" Version="6.12.1" />
3940
<PackageVersion Include="protobuf-net" Version="3.2.26" />
4041
<PackageVersion Include="protobuf-net.Core" Version="3.2.26" />
4142
<PackageVersion Include="protobuf-net.Grpc" Version="1.1.1" />

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ These settings are available in addition to the [Common Settings](#common-settin
148148
| `$(MSBuildCacheBlobUri)` | `Uri` | | Specifies the uri of the Azure Storage Blob. |
149149
| `$(MSBuildCacheManagedIdentityClientId)` | `string` | | Specifies the managed identity client id when using the "ManagedIdentity" credential type |
150150
| `$(MSBuildCacheInteractiveAuthTokenDirectory)` | `string` | "%LOCALAPPDATA%\MSBuildCache\AuthTokenCache" | Specifies a token cache directory when using the "Interactive" credential type |
151+
| `$(MSBuildCacheIgnoreDotNetSdkPatchVersion)` | `bool` | false | Whether to ignore the patch version when doing cache lookups. This trades off some correctness for the sake of getting cache hits when the SDK version isn't exactly the same. The default behavior is to consider the exact SDK version, eg. "8.0.404". With this setting set to true, it will instead use something like "8.0.4XX". Note that the major version, minor version, and feature bands are still considered. |
151152

152153
When using the "ConnectionString" credential type, the connection string to the blob storage account must be provided in the `MSBCACHE_CONNECTIONSTRING` environment variable. This connection string needs both read and write access to the resource.
153154

src/Common.Tests/PluginSettingsTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ public void GetResultsForUnqueriedDependenciesSetting()
168168
public void TargetsToIgnoreSetting(StringListTestCase testCase)
169169
=> TestStringListSetting(nameof(PluginSettings.TargetsToIgnore), testCase, pluginSettings => pluginSettings.TargetsToIgnore);
170170

171+
[TestMethod]
172+
public void IgnoreDotNetSdkPatchVersionSetting()
173+
=> TestBoolSetting(nameof(PluginSettings.IgnoreDotNetSdkPatchVersion), pluginSettings => pluginSettings.IgnoreDotNetSdkPatchVersion);
174+
171175
private static void TestBoolSetting(string settingName, Func<PluginSettings, bool> valueAccessor)
172176
=> TestBasicSetting(
173177
settingName,

src/Common/Fingerprinting/FingerprintFactory.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using BuildXL.Cache.ContentStore.Interfaces.Extensions;
1313
using DotNet.Globbing;
1414
using Microsoft.MSBuildCache.Hashing;
15+
using NuGet.Versioning;
1516

1617
namespace Microsoft.MSBuildCache.Fingerprinting;
1718

@@ -111,7 +112,20 @@ void AddSettingToFingerprint(IReadOnlyCollection<Glob>? patterns, string setting
111112
string dotnetSdkVersion = nodeContext.ProjectInstance.GetPropertyValue("NETCoreSdkVersion");
112113
if (!string.IsNullOrEmpty(dotnetSdkVersion))
113114
{
114-
entries.Add(CreateFingerprintEntry($"DotnetSdkVersion: {dotnetSdkVersion}"));
115+
if (_pluginSettings.IgnoreDotNetSdkPatchVersion
116+
&& NuGetVersion.TryParse(dotnetSdkVersion, out NuGetVersion? parsedDotnetSdkVersion))
117+
{
118+
// The "feature band" indicates the feature set and is aligned with the Visual Studio version. It's "C00" in a version like A.B.CDD
119+
// Extract it by removing the last two digits of the patch number, eg 123 -> 1.
120+
int featureBand = parsedDotnetSdkVersion.Patch / 100;
121+
122+
// Eg: "8.0.404" -> "8.0.4XX", or "9.0.100-rc.2.24474.11" -> "9.0.100"
123+
entries.Add(CreateFingerprintEntry($"DotnetSdkVersion: {parsedDotnetSdkVersion.Major}.{parsedDotnetSdkVersion.Minor}.{featureBand}XX"));
124+
}
125+
else
126+
{
127+
entries.Add(CreateFingerprintEntry($"DotnetSdkVersion: {dotnetSdkVersion}"));
128+
}
115129
}
116130

117131
// Add predicted inputs

src/Common/Microsoft.MSBuildCache.Common.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<PackageReference Include="Microsoft.BuildXL.Cache.ContentStore.Interfaces" />
1616
<PackageReference Include="Microsoft.BuildXL.Cache.MemoizationStore.Interfaces" />
1717
<PackageReference Include="Microsoft.BuildXL.Cache.MemoizationStore.Library" />
18+
<PackageReference Include="NuGet.Versioning" />
1819
<PackageReference Include="System.Threading.Channels" />
1920
</ItemGroup>
2021
<ItemGroup>

src/Common/PluginSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ public string LocalCacheRootPath
105105

106106
public IReadOnlyList<string> TargetsToIgnore { get; init; } = Array.Empty<string>();
107107

108+
public bool IgnoreDotNetSdkPatchVersion { get; init; }
109+
108110
public static T Create<T>(
109111
IReadOnlyDictionary<string, string> settings,
110112
PluginLoggerBase logger,

src/Common/build/Microsoft.MSBuildCache.Common.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheGlobalPropertiesToIgnore</MSBuildCacheGlobalPropertiesToIgnore>
2323
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheGetResultsForUnqueriedDependencies</MSBuildCacheGlobalPropertiesToIgnore>
2424
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheTargetsToIgnore</MSBuildCacheGlobalPropertiesToIgnore>
25+
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheIgnoreDotNetSdkPatchVersion</MSBuildCacheGlobalPropertiesToIgnore>
2526
</PropertyGroup>
2627

2728
<ItemGroup Condition="'$(MSBuildCacheEnabled)' != 'false'">
@@ -43,6 +44,7 @@
4344
<GlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore)</GlobalPropertiesToIgnore>
4445
<GetResultsForUnqueriedDependencies>$(MSBuildCacheGetResultsForUnqueriedDependencies)</GetResultsForUnqueriedDependencies>
4546
<TargetsToIgnore>$(MSBuildCacheTargetsToIgnore)</TargetsToIgnore>
47+
<IgnoreDotNetSdkPatchVersion>$(MSBuildCacheIgnoreDotNetSdkPatchVersion)</IgnoreDotNetSdkPatchVersion>
4648
</ProjectCachePlugin>
4749
</ItemGroup>
4850

0 commit comments

Comments
 (0)