|
5 | 5 | <IsPackable>false</IsPackable>
|
6 | 6 | </PropertyGroup>
|
7 | 7 |
|
| 8 | + <!-- |
| 9 | + The MVVM Toolkit source generators rely on Roslyn multi-targeting to support multiple versions of the Microsoft.CodeAnalysis.CSharp package. |
| 10 | + This package reference actually needs a matching version of Roslyn to be available for consumers of the source generator, so if we always |
| 11 | + used the latest version, the MVVM Toolkit would just fail to load for users of eg. an older version of Visual Studio. Thankfully, Roslyn |
| 12 | + supports analyzers that bundle multiple versions in the same NuGet package, each in a subfolder with a name matching the Roslyn version. |
| 13 | + To leverage this, this project receives the MvvmToolkitSourceGeneratorRoslynVersion property as input, so that the MVVM Toolkit can build |
| 14 | + it multiple times with multiple versions during packing, to then extract each .dll and copy it to the right NuGet package folder. |
| 15 | + --> |
| 16 | + <PropertyGroup> |
| 17 | + |
| 18 | + <!-- When the property is not set (which will not happen when creating a NuGet package anyway), just default to 4.0.1 --> |
| 19 | + <MvvmToolkitSourceGeneratorRoslynVersion Condition="'$(MvvmToolkitSourceGeneratorRoslynVersion)' == ''">4.0.1</MvvmToolkitSourceGeneratorRoslynVersion> |
| 20 | + |
| 21 | + <!-- The output path will end up being eg. "bin\Debug\roslyn4.0\netstandard2.0" (the trailing "netstandard2.0" is added automatically) --> |
| 22 | + <OutputPath>bin\$(Configuration)\roslyn$(MvvmToolkitSourceGeneratorRoslynVersion.Substring(0, 3))</OutputPath> |
| 23 | + |
| 24 | + <!-- Also define a "ROSLYN_<MAJOR>_<MINOR>" build constant, so the generator code can multi-target whenever needed and add any required polyfills --> |
| 25 | + <DefineConstants>$(DefineConstants);ROSLYN_$(MvvmToolkitSourceGeneratorRoslynVersion.Substring(0, 3).Replace('.', '_'))</DefineConstants> |
| 26 | + </PropertyGroup> |
| 27 | + |
8 | 28 | <ItemGroup>
|
9 | 29 | <Compile Remove="EmbeddedResources\INotifyPropertyChanged.cs" />
|
10 | 30 | <Compile Remove="EmbeddedResources\NotNullAttribute.cs" />
|
|
32 | 52 | </ItemGroup>
|
33 | 53 |
|
34 | 54 | <ItemGroup>
|
35 |
| - <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" PrivateAssets="all" Pack="false" /> |
| 55 | + <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MvvmToolkitSourceGeneratorRoslynVersion)" PrivateAssets="all" Pack="false" /> |
36 | 56 | </ItemGroup>
|
37 | 57 |
|
38 | 58 | <ItemGroup>
|
|
0 commit comments