Skip to content

Commit

Permalink
Update targets file to ensure newtonsoft update can cater to more sce…
Browse files Browse the repository at this point in the history
…narios.
  • Loading branch information
aavasthy committed Oct 30, 2024
1 parent 8ef1a80 commit 2fd3f8c
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions Microsoft.Azure.Cosmos/src/Microsoft.Azure.Cosmos.targets
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,44 @@ Copyright (C) Microsoft Corporation. All rights reserved.
</ItemGroup>


<!-- Add check for Newtonsoft.Json package in cosnumer app. -->
<Target Name="CheckNewtonsoftJsonVersion" BeforeTargets="CoreCompile" Condition="'$(ExcludeRestorePackageImports)' != 'true'">

<!-- Add check for Newtonsoft.Json package in consumer app. -->
<Target Name="CheckNewtonsoftJsonPresence" BeforeTargets="CoreCompile" Condition="'$(ExcludeRestorePackageImports)' != 'true'">

<!-- Allow consumers to disable this check -->
<PropertyGroup>
<DisableNewtonsoftJsonCheck Condition="'$(DisableNewtonsoftJsonCheck)' == ''">false</DisableNewtonsoftJsonCheck>
</PropertyGroup>

<!-- Check for PackageReference to Newtonsoft.Json -->
<ItemGroup>
<NewtonsoftJsonPackageReference Include="@(PackageReference)" Condition="'%(PackageReference.Identity)' == 'Newtonsoft.Json'" />
</ItemGroup>
<!-- If Newtonsoft.Json is not referenced, fail the build -->
<Error Text="The Newtonsoft.Json package must be explicitly referenced with version >= 10.0.2."
Condition="'@(NewtonsoftJsonPackageReference)' == ''" />


<!-- Check for assembly references to Newtonsoft.Json (including transitive dependencies) -->
<ItemGroup>
<NewtonsoftJsonAssemblyReference Include="@(ReferencePath)" Condition="'%(FileName)' == 'Newtonsoft.Json'" />
</ItemGroup>

<!-- Check for Newtonsoft.Json in packages.config -->
<PropertyGroup>
<PackagesConfigPath>packages.config</PackagesConfigPath>
<NewtonsoftJsonInPackagesConfig>false</NewtonsoftJsonInPackagesConfig>
</PropertyGroup>

<XmlPeek Condition="Exists('$(PackagesConfigPath)')"
XmlInputPath="$(PackagesConfigPath)"
Query="/packages/package[@id='Newtonsoft.Json']">
<Output TaskParameter="Result" PropertyName="NewtonsoftJsonPackagesConfigResult" />
</XmlPeek>

<PropertyGroup>
<NewtonsoftJsonInPackagesConfig Condition="'$(NewtonsoftJsonPackagesConfigResult)' != ''">true</NewtonsoftJsonInPackagesConfig>
</PropertyGroup>

<!-- Produce an error if Newtonsoft.Json is not found and the check is not disabled -->
<Error Text="The Newtonsoft.Json package must be explicitly referenced with version >= 10.0.2. Please add a reference to Newtonsoft.Json, or set the 'DisableNewtonsoftJsonCheck' property to 'true' to bypass this check."
Condition="'$(DisableNewtonsoftJsonCheck)' != 'true' and '@(NewtonsoftJsonPackageReference)' == '' and '@(NewtonsoftJsonAssemblyReference)' == '' and '$(NewtonsoftJsonInPackagesConfig)' != 'true'" />

</Target>

</Project>

0 comments on commit 2fd3f8c

Please sign in to comment.