-
-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathDirectory.Build.targets
More file actions
33 lines (28 loc) 路 1.78 KB
/
Copy pathDirectory.Build.targets
File metadata and controls
33 lines (28 loc) 路 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<Project>
<!-- Prove the file is imported -->
<Target Name="__Diag_DirectoryBuildTargets_Imported" BeforeTargets="Build">
<Message Importance="High" Text="Directory.Build.targets loaded for $(MSBuildProjectName)" />
</Target>
<!-- This target blocks unwanted NuGet package versions across the solution -->
<Target Name="BlockUnwantedDependencies" AfterTargets="ResolvePackageAssets;ResolveReferences">
<ItemGroup>
<!-- Collect as many resolved items as possible to ensure NuGet metadata is present -->
<_AllResolvedFromPackages Include="@(ReferencePath)" />
<_AllResolvedFromPackages Include="@(ReferenceCopyLocalPaths)" />
<_AllResolvedFromPackages Include="@(ResolvedCompileFileDefinitions)" />
<_AllResolvedFromPackages Include="@(RuntimeCopyLocalItems)" />
<_AllResolvedFromPackages Include="@(ResolvedFileToPublish)" />
<!-- Rule: block FluentAssertions >= 8.0.0 -->
<_Unwanted Include="@(_AllResolvedFromPackages)"
Condition="'%(_AllResolvedFromPackages.NuGetPackageId)' == 'FluentAssertions'
AND $([MSBuild]::VersionGreaterThanOrEquals('%(_AllResolvedFromPackages.NuGetPackageVersion)', '8.0.0'))" />
</ItemGroup>
<!-- Optional: log any detected blocked packages -->
<Message Importance="High"
Text="Blocked package detected: %(_Unwanted.NuGetPackageId) v%(_Unwanted.NuGetPackageVersion) in $(MSBuildProjectName)"
Condition="'@(_Unwanted)' != ''" />
<!-- Fail the build for each offending item (escape < and > in XML attributes!) -->
<Error Text="Package %(_Unwanted.NuGetPackageId) v%(_Unwanted.NuGetPackageVersion) is not allowed. Please downgrade (e.g., FluentAssertions < 8.0.0)."
Condition="'@(_Unwanted)' != ''" />
</Target>
</Project>