Skip to content

Commit 14b7672

Browse files
committed
Manually look for a packages.config file in builds
1 parent 9a671aa commit 14b7672

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/CommunityToolkit.Mvvm/CommunityToolkit.Mvvm.targets

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,35 @@
106106
<Target Name="MVVMToolkitWarnForPackagesConfigUse"
107107
AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets"
108108
DependsOnTargets="MVVMToolkitGatherAnalyzers">
109-
109+
110110
<!--
111-
Emit a warning in case packages.config is used, by reading the associated MSBuild property.
111+
Check whether packages are being restored via packages.config, by reading the associated MSBuild property.
112112
This happens when either the project style is using packages.config, or when explicitly requested.
113113
See https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#restoring-packagereference-and-packagesconfig-projects-with-msbuild.
114114
-->
115-
<Warning Condition ="'$(RestorePackagesConfig)' == 'true' OR '$(RestoreProjectStyle)' == 'PackagesConfig'"
115+
<PropertyGroup>
116+
<MVVMToolkitIsTargetProjectUsingPackagesConfig Condition ="'$(RestorePackagesConfig)' == 'true' OR '$(RestoreProjectStyle)' == 'PackagesConfig'">true</MVVMToolkitIsTargetProjectUsingPackagesConfig>
117+
</PropertyGroup>
118+
119+
<!--
120+
If no packages.config properties are set, also try to manually find the packages.config file.
121+
This will be in the @(None) elements, if present. Doing so makes sure this works in builds as
122+
well, since the implicit targets populating the properties above only run when restoring.
123+
-->
124+
<FindInList ItemSpecToFind="packages.config"
125+
List="@(None)"
126+
MatchFileNameOnly="false"
127+
Condition="'$(MVVMToolkitIsTargetProjectUsingPackagesConfig)' != 'true'">
128+
<Output TaskParameter="ItemFound" PropertyName="MVVMToolkitPackagesConfigFile"/>
129+
</FindInList>
130+
131+
<!-- Make sure to update the MSBuild property if the above task did find something -->
132+
<PropertyGroup>
133+
<MVVMToolkitIsTargetProjectUsingPackagesConfig Condition ="'$(MVVMToolkitPackagesConfigFile)' == 'packages.config'">true</MVVMToolkitIsTargetProjectUsingPackagesConfig>
134+
</PropertyGroup>
135+
136+
<!-- Emit a warning in case packages.config is used -->
137+
<Warning Condition ="'$(MVVMToolkitIsTargetProjectUsingPackagesConfig)' == 'true'"
116138
Code="MVVMTKCFG0002"
117139
HelpLink="https://aka.ms/mvvmtoolkit/errors/mvvmtkcfg0002"
118140
Text="The MVVM Toolkit source generators might not be loaded correctly, as the current project is using the packages.config setup to restore NuGet packages. Source generators require PackageReference to be used (either in a legacy-style or SDK-style .csproj project, both are supported as long as PackageReference is used)."/>

0 commit comments

Comments
 (0)