|
106 | 106 | <Target Name="MVVMToolkitWarnForPackagesConfigUse"
|
107 | 107 | AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets"
|
108 | 108 | DependsOnTargets="MVVMToolkitGatherAnalyzers">
|
109 |
| - |
| 109 | + |
110 | 110 | <!--
|
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. |
112 | 112 | This happens when either the project style is using packages.config, or when explicitly requested.
|
113 | 113 | See https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#restoring-packagereference-and-packagesconfig-projects-with-msbuild.
|
114 | 114 | -->
|
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'" |
116 | 138 | Code="MVVMTKCFG0002"
|
117 | 139 | HelpLink="https://aka.ms/mvvmtoolkit/errors/mvvmtkcfg0002"
|
118 | 140 | 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