Skip to content

Commit f20f44b

Browse files
Merge pull request #438 from reduckted/feature/newtonsoft-json-detection
Skipped the Newtonsoft.Json version when using the newer VS SDK. [release]
2 parents daf6122 + 52d2365 commit f20f44b

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/toolkit/nuget/build/imports/NewtonsoftJsonVersionCheck.targets

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,45 @@
11
<Project>
22

3-
<Target Name="NewtonsoftJsonVersionCheck" AfterTargets="ResolveReferences">
3+
<Target Name="NewtonsoftJsonVersionCheck" AfterTargets="ResolveReferences" Condition="'$(CheckNewtonsoftJsonVersion)' != 'false'">
44
<ItemGroup>
55
<!--
66
Any NuGet packages that are referenced (even transitive references) are in the `Reference`
77
item. For NuGet packages, there will be `NuGetPackageId` and `NuGetPackageVersion` metadata.
88
Filter the list of references to get the version of Newtonsoft.Json that is referenced (if any).
99
-->
1010
<CVST_NewtonsoftJsonReferenceVersion Include="%(Reference.NuGetPackageVersion)" Condition="'%(Reference.NuGetPackageId)' == 'Newtonsoft.Json'"/>
11+
12+
<!--
13+
We also need the version of the `Microsoft.VisualStudio.SDK`package. That is a
14+
meta package, so it doesn't end up in the `Reference` items. We can get it from the
15+
`PackageReference` items instead, however that does rely on it being explicitly referenced.
16+
-->
17+
<CVST_VisualStudioSdkReferenceVersion Include="%(PackageReference.Version)" Condition="'%(PackageReference.Identity)' == 'Microsoft.VisualStudio.SDK'"/>
1118
</ItemGroup>
1219

1320
<PropertyGroup>
1421
<!-- Turn the item list of version numbers into a single property value. -->
1522
<CVST_NewtonsoftJsonVersion>@(CVST_NewtonsoftJsonReferenceVersion)</CVST_NewtonsoftJsonVersion>
16-
23+
<CVST_VisualStudioSdkVersion>@(CVST_VisualStudioSdkReferenceVersion)</CVST_VisualStudioSdkVersion>
24+
1725
<!--
26+
The latest versions of the Visual Studio SDK explicitly reference `Newtonsoft.Json`,
27+
which means NuGet will raise warnings if a newer version of `Newtonsoft.Json` is installed.
28+
That means we can skip the version check if the Visual Studio SDK is above a certain
29+
version. We can skip the check by clearing the `CVST_NewtonsoftJsonVersion` property.
30+
-->
31+
<CVST_NewtonsoftJsonSdkMaxVersion>17.5.33428.388</CVST_NewtonsoftJsonSdkMaxVersion>
32+
<CVST_NewtonsoftJsonHasModernSdk Condition="( '$(CVST_NewtonsoftJsonSdkMaxVersion)' != '' ) AND ( '$(CVST_VisualStudioSdkVersion)' != '' ) AND ( '$(CVST_VersionPropertyFunctionsExist)' == 'true' )">$([MSBuild]::VersionGreaterThan('$(CVST_VisualStudioSdkVersion)', '$(CVST_NewtonsoftJsonSdkMaxVersion)'))</CVST_NewtonsoftJsonHasModernSdk>
33+
<CVST_NewtonsoftJsonHasModernSdk Condition="( '$(CVST_NewtonsoftJsonSdkMaxVersion)' != '' ) AND ( '$(CVST_VisualStudioSdkVersion)' != '' ) AND ( '$(CVST_VersionPropertyFunctionsExist)' != 'true' ) AND ( $(CVST_VisualStudioSdkVersion) &gt; $(CVST_NewtonsoftJsonSdkMaxVersion) )">true</CVST_NewtonsoftJsonHasModernSdk>
34+
<CVST_NewtonsoftJsonVersion Condition="$(CVST_NewtonsoftJsonHasModernSdk) == 'true'"></CVST_NewtonsoftJsonVersion>
35+
36+
<!--
1837
The property functions for version comparisons are the preferred way to compare versions,
1938
but they are not available in older versions of MSBuild. In earlier versions we can compare
2039
the version values directly, although that is not always accurate.
2140
See: https://docs.microsoft.com/visualstudio/msbuild/msbuild-conditions#comparing-versions
2241
-->
42+
<CVST_NewtonsoftJsonIsValid>true</CVST_NewtonsoftJsonIsValid>
2343
<CVST_NewtonsoftJsonIsValid Condition="( '$(CVST_NewtonsoftJsonVersion)' != '' ) AND ( '$(CVST_VersionPropertyFunctionsExist)' == 'true' )">$([MSBuild]::VersionLessThanOrEquals('$(CVST_NewtonsoftJsonVersion)', '$(CVST_NewtonsoftJsonMaxVersion)'))</CVST_NewtonsoftJsonIsValid>
2444
<CVST_NewtonsoftJsonIsValid Condition="( '$(CVST_NewtonsoftJsonVersion)' != '' ) AND ( '$(CVST_VersionPropertyFunctionsExist)' != 'true' ) AND ( $(CVST_NewtonsoftJsonVersion) &lt;= $(CVST_NewtonsoftJsonMaxVersion) )">true</CVST_NewtonsoftJsonIsValid>
2545

0 commit comments

Comments
 (0)