Skip to content

Commit

Permalink
Add setting to opt-into ignoring the .NET SDK patch version (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfederm authored Nov 15, 2024
1 parent 147bc0b commit c1faabb
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
<PackageVersion Include="Microsoft.VisualStudio.Services.BlobStore.Client" Version="$(ArtifactsPackageVersion)" />
<PackageVersion Include="Microsoft.VisualStudio.Services.BlobStore.Client.Cache" Version="$(ArtifactsPackageVersion)" />
<PackageVersion Include="Microsoft.VisualStudio.Services.PipelineCache.WebApi" Version="$(ArtifactsPackageVersion)" />
<PackageVersion Include="morelinq" Version="3.4.2" />
<PackageVersion Include="MSTest" Version="3.5.0" />
<!--
An indirect dependency of BXL (Minimatch) depends on a very old and non-existing version of NETStandard.Library (>= 1.0.0-rc2-23910).
This forces a good version of NETStandard.Library to mitigate.
-->
<PackageVersion Include="NETStandard.Library" Version="2.0.3"/>
<PackageVersion Include="morelinq" Version="3.4.2" />
<PackageVersion Include="NuGet.Versioning" Version="6.12.1" />
<PackageVersion Include="protobuf-net" Version="3.2.26" />
<PackageVersion Include="protobuf-net.Core" Version="3.2.26" />
<PackageVersion Include="protobuf-net.Grpc" Version="1.1.1" />
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ These settings are available in addition to the [Common Settings](#common-settin
| `$(MSBuildCacheBlobUri)` | `Uri` | | Specifies the uri of the Azure Storage Blob. |
| `$(MSBuildCacheManagedIdentityClientId)` | `string` | | Specifies the managed identity client id when using the "ManagedIdentity" credential type |
| `$(MSBuildCacheInteractiveAuthTokenDirectory)` | `string` | "%LOCALAPPDATA%\MSBuildCache\AuthTokenCache" | Specifies a token cache directory when using the "Interactive" credential type |
| `$(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. |

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.

Expand Down
4 changes: 4 additions & 0 deletions src/Common.Tests/PluginSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ public void GetResultsForUnqueriedDependenciesSetting()
public void TargetsToIgnoreSetting(StringListTestCase testCase)
=> TestStringListSetting(nameof(PluginSettings.TargetsToIgnore), testCase, pluginSettings => pluginSettings.TargetsToIgnore);

[TestMethod]
public void IgnoreDotNetSdkPatchVersionSetting()
=> TestBoolSetting(nameof(PluginSettings.IgnoreDotNetSdkPatchVersion), pluginSettings => pluginSettings.IgnoreDotNetSdkPatchVersion);

private static void TestBoolSetting(string settingName, Func<PluginSettings, bool> valueAccessor)
=> TestBasicSetting(
settingName,
Expand Down
16 changes: 15 additions & 1 deletion src/Common/Fingerprinting/FingerprintFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using BuildXL.Cache.ContentStore.Interfaces.Extensions;
using DotNet.Globbing;
using Microsoft.MSBuildCache.Hashing;
using NuGet.Versioning;

namespace Microsoft.MSBuildCache.Fingerprinting;

Expand Down Expand Up @@ -111,7 +112,20 @@ void AddSettingToFingerprint(IReadOnlyCollection<Glob>? patterns, string setting
string dotnetSdkVersion = nodeContext.ProjectInstance.GetPropertyValue("NETCoreSdkVersion");
if (!string.IsNullOrEmpty(dotnetSdkVersion))
{
entries.Add(CreateFingerprintEntry($"DotnetSdkVersion: {dotnetSdkVersion}"));
if (_pluginSettings.IgnoreDotNetSdkPatchVersion
&& NuGetVersion.TryParse(dotnetSdkVersion, out NuGetVersion? parsedDotnetSdkVersion))
{
// 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
// Extract it by removing the last two digits of the patch number, eg 123 -> 1.
int featureBand = parsedDotnetSdkVersion.Patch / 100;

// Eg: "8.0.404" -> "8.0.4XX", or "9.0.100-rc.2.24474.11" -> "9.0.100"
entries.Add(CreateFingerprintEntry($"DotnetSdkVersion: {parsedDotnetSdkVersion.Major}.{parsedDotnetSdkVersion.Minor}.{featureBand}XX"));
}
else
{
entries.Add(CreateFingerprintEntry($"DotnetSdkVersion: {dotnetSdkVersion}"));
}
}

// Add predicted inputs
Expand Down
1 change: 1 addition & 0 deletions src/Common/Microsoft.MSBuildCache.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageReference Include="Microsoft.BuildXL.Cache.ContentStore.Interfaces" />
<PackageReference Include="Microsoft.BuildXL.Cache.MemoizationStore.Interfaces" />
<PackageReference Include="Microsoft.BuildXL.Cache.MemoizationStore.Library" />
<PackageReference Include="NuGet.Versioning" />
<PackageReference Include="System.Threading.Channels" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/Common/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public string LocalCacheRootPath

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

public bool IgnoreDotNetSdkPatchVersion { get; init; }

public static T Create<T>(
IReadOnlyDictionary<string, string> settings,
PluginLoggerBase logger,
Expand Down
2 changes: 2 additions & 0 deletions src/Common/build/Microsoft.MSBuildCache.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheGlobalPropertiesToIgnore</MSBuildCacheGlobalPropertiesToIgnore>
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheGetResultsForUnqueriedDependencies</MSBuildCacheGlobalPropertiesToIgnore>
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheTargetsToIgnore</MSBuildCacheGlobalPropertiesToIgnore>
<MSBuildCacheGlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore);MSBuildCacheIgnoreDotNetSdkPatchVersion</MSBuildCacheGlobalPropertiesToIgnore>
</PropertyGroup>

<ItemGroup Condition="'$(MSBuildCacheEnabled)' != 'false'">
Expand All @@ -43,6 +44,7 @@
<GlobalPropertiesToIgnore>$(MSBuildCacheGlobalPropertiesToIgnore)</GlobalPropertiesToIgnore>
<GetResultsForUnqueriedDependencies>$(MSBuildCacheGetResultsForUnqueriedDependencies)</GetResultsForUnqueriedDependencies>
<TargetsToIgnore>$(MSBuildCacheTargetsToIgnore)</TargetsToIgnore>
<IgnoreDotNetSdkPatchVersion>$(MSBuildCacheIgnoreDotNetSdkPatchVersion)</IgnoreDotNetSdkPatchVersion>
</ProjectCachePlugin>
</ItemGroup>

Expand Down

0 comments on commit c1faabb

Please sign in to comment.