This was finally fixed in Visual Studio 17.8.4. It did not work in 17.8.3.
This is the .csproj
for my generator project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageReference Include="Scriban" Version="5.9.1" GeneratePathProperty="true" />
</ItemGroup>
<PropertyGroup>
<GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn>
</PropertyGroup>
<Target Name="GetDependencyTargetPaths">
<ItemGroup>
<TargetPathWithTargetPlatformMoniker Include="$(PKGScriban)\lib\netstandard2.0\Scriban.dll" IncludeRuntimeDependency="false" />
</ItemGroup>
</Target>
</Project>
Contrary to various tutorials, I did not find it necessary to use PrivateAssets="all"
here.
My consumer resides in the same solution and references the generator with a ProjectReference
:
<ItemGroup>
<ProjectReference Include="..\TestGenerator\TestGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
AddSource
. If I deliberately introduce an error in the generated source, the target project reports that error and no longer builds. But the dependency tree in the Solution Explorer says the generator is not generating source, which is clearly wrong. – Jemmie