Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<!--
The MVVM Toolkit source generators rely on Roslyn multi-targeting to support multiple versions of the Microsoft.CodeAnalysis.CSharp package.
This package reference actually needs a matching version of Roslyn to be available for consumers of the source generator, so if we always
used the latest version, the MVVM Toolkit would just fail to load for users of eg. an older version of Visual Studio. Thankfully, Roslyn
supports analyzers that bundle multiple versions in the same NuGet package, each in a subfolder with a name matching the Roslyn version.
To leverage this, this project receives the MvvmToolkitSourceGeneratorRoslynVersion property as input, so that the MVVM Toolkit can build
it multiple times with multiple versions during packing, to then extract each .dll and copy it to the right NuGet package folder.
-->
<PropertyGroup>

<!-- When the property is not set (which will not happen when creating a NuGet package anyway), just default to 4.0.1 -->
<MvvmToolkitSourceGeneratorRoslynVersion Condition="'$(MvvmToolkitSourceGeneratorRoslynVersion)' == ''">4.0.1</MvvmToolkitSourceGeneratorRoslynVersion>

<!--
The output path will end up being eg. "bin\Debug\roslyn4.0\netstandard2.0" (the trailing "netstandard2.0" is added automatically).
This is only set when $(MvvmToolkitIsGeneratingNuGetPackage) is set (when packing CommunityToolkit.Mvvm). This avoids unit test issues.
-->
<OutputPath Condition="'$(MvvmToolkitIsGeneratingNuGetPackage)' == 'true'">bin\$(Configuration)\roslyn$(MvvmToolkitSourceGeneratorRoslynVersion.Substring(0, 3))\</OutputPath>

<!-- Also define a "ROSLYN_<MAJOR>_<MINOR>" build constant, so the generator code can multi-target whenever needed and add any required polyfills -->
<DefineConstants>$(DefineConstants);ROSLYN_$(MvvmToolkitSourceGeneratorRoslynVersion.Substring(0, 3).Replace('.', '_'))</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Remove="EmbeddedResources\INotifyPropertyChanged.cs" />
<Compile Remove="EmbeddedResources\NotNullAttribute.cs" />
Expand Down Expand Up @@ -32,7 +55,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" PrivateAssets="all" Pack="false" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MvvmToolkitSourceGeneratorRoslynVersion)" PrivateAssets="all" Pack="false" />
</ItemGroup>

<ItemGroup>
Expand Down
20 changes: 13 additions & 7 deletions CommunityToolkit.Mvvm/CommunityToolkit.Mvvm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>

<!-- Source generator project reference for packing -->
<!-- Reference the various multi-targeted versions of the source generator project (one per Roslyn version) -->
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<ProjectReference Include="..\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.csproj" ReferenceOutputAssembly="false">
<Properties>MvvmToolkitSourceGeneratorRoslynVersion=4.0.1;MvvmToolkitIsGeneratingNuGetPackage=true</Properties>
</ProjectReference>
<ProjectReference Include="..\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.csproj" ReferenceOutputAssembly="false">
<Properties>MvvmToolkitSourceGeneratorRoslynVersion=4.3.0;MvvmToolkitIsGeneratingNuGetPackage=true</Properties>
</ProjectReference>
</ItemGroup>

<ItemGroup Label="Package">
Expand All @@ -53,11 +58,12 @@
<None Include="CommunityToolkit.Mvvm.targets" PackagePath="build\netstandard2.0" Pack="true" />
<None Include="CommunityToolkit.Mvvm.targets" PackagePath="build\netstandard2.1" Pack="true" />

<!-- Pack the source generator to the right package folder -->
<None Include="..\CommunityToolkit.Mvvm.SourceGenerators\bin\$(Configuration)\netstandard2.0\CommunityToolkit.Mvvm.SourceGenerators.dll"
PackagePath="analyzers\dotnet\roslyn4.0\cs"
Pack="true"
Visible="false" />
<!--
Pack the source generator to the right package folders (each matching the target Roslyn version).
Roslyn will automatically load the highest version compatible with Roslyn's version in the SDK.
-->
<None Include="..\CommunityToolkit.Mvvm.SourceGenerators\bin\$(Configuration)\roslyn4.0\netstandard2.0\CommunityToolkit.Mvvm.SourceGenerators.dll" PackagePath="analyzers\dotnet\roslyn4.0\cs" Pack="true" Visible="false" />
<None Include="..\CommunityToolkit.Mvvm.SourceGenerators\bin\$(Configuration)\roslyn4.3\netstandard2.0\CommunityToolkit.Mvvm.SourceGenerators.dll" PackagePath="analyzers\dotnet\roslyn4.3\cs" Pack="true" Visible="false" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ jobs:
- script: dotnet test -c Release -f net6.0 -l "trx;LogFileName=VSTestResults_net6.0.trx"
displayName: Run .NET 6 unit tests

# Run the .NET 6 MVVM Toolkit tests targeting Roslyn 4.0.1
- script: dotnet test tests\CommunityToolkit.Mvvm.UnitTests\CommunityToolkit.Mvvm.UnitTests.csproj -c Release -f net6.0 -l "trx;LogFileName=VSTestResults_net6.0_mvvmtoolkit_roslyn401.trx"
displayName: Run CommunityToolkit.Mvvm.UnitTests unit tests with Roslyn 4.0.1

# Run the .NET 6 MVVM Toolkit source generator tests targeting Roslyn 4.0.1
- script: dotnet test tests\CommunityToolkit.Mvvm.SourceGenerators.UnitTests\CommunityToolkit.Mvvm.SourceGenerators.UnitTests.csproj -c Release -f net6.0 -l "trx;LogFileName=VSTestResults_net6.0_mvvmtoolkit_generators_roslyn401.trx"
displayName: Run CommunityToolkit.Mvvm.UnitTests unit tests with Roslyn 4.0.1

# Run .NET Core 3.1 tests
- script: dotnet test -c Release -f netcoreapp3.1 -l "trx;LogFileName=VSTestResults_netcoreapp3.1.trx"
displayName: Run .NET Core 3.1 unit tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
<NoWarn>$(NoWarn);CS8002;SA0001</NoWarn>
</PropertyGroup>

<!-- See comments in CommunityToolkit.MvvmUnitTests -->
<PropertyGroup>
<MvvmToolkitSourceGeneratorRoslynVersion Condition="'$(MvvmToolkitSourceGeneratorRoslynVersion)' == ''">4.3.0</MvvmToolkitSourceGeneratorRoslynVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\CommunityToolkit.Mvvm\CommunityToolkit.Mvvm.csproj" />
<ProjectReference Include="..\..\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build">
<Properties>MvvmToolkitSourceGeneratorRoslynVersion=$(MvvmToolkitSourceGeneratorRoslynVersion)</Properties>
</ProjectReference>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net472;netcoreapp3.1;net6.0</TargetFrameworks>
Expand All @@ -11,9 +11,15 @@
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
</ItemGroup>

<!-- See comments in CommunityToolkit.MvvmUnitTests -->
<PropertyGroup>
<MvvmToolkitSourceGeneratorRoslynVersion Condition="'$(MvvmToolkitSourceGeneratorRoslynVersion)' == ''">4.3.0</MvvmToolkitSourceGeneratorRoslynVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.csproj" />
<ProjectReference Include="..\..\CommunityToolkit.Mvvm\CommunityToolkit.Mvvm.csproj" />
<ProjectReference Include="..\..\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.csproj">
<Properties>MvvmToolkitSourceGeneratorRoslynVersion=$(MvvmToolkitSourceGeneratorRoslynVersion)</Properties>
</ProjectReference>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\CommunityToolkit.Mvvm\CommunityToolkit.Mvvm.csproj" />
<ProjectReference Include="..\..\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\CommunityToolkit.Mvvm.ExternalAssembly\CommunityToolkit.Mvvm.ExternalAssembly.csproj" />
</ItemGroup>

<!-- Since the MVVM Toolkit generator uses multi-targeting for Roslyn versions, we also want to test all of them here -->
<PropertyGroup>
<MvvmToolkitSourceGeneratorRoslynVersion Condition="'$(MvvmToolkitSourceGeneratorRoslynVersion)' == ''">4.3.0</MvvmToolkitSourceGeneratorRoslynVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\CommunityToolkit.Mvvm\CommunityToolkit.Mvvm.csproj" />
<ProjectReference Include="..\..\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build">
<Properties>MvvmToolkitSourceGeneratorRoslynVersion=$(MvvmToolkitSourceGeneratorRoslynVersion)</Properties>
</ProjectReference>
</ItemGroup>

</Project>