I have my source generator project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AnalyzerRoslynVersion>4.4</AnalyzerRoslynVersion>
<TargetFramework>netstandard2.0</TargetFramework>
<Nullable>enable</Nullable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.7.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>
</Project>
In the assembly Domain.Core I have defined the marker attribute.
[AttributeUsage(AttributeTargets.Class)]
public class EventApplyAttribute : Attribute
{
public string FullyQualifiedAggregateName { get; }
public EventApplyAttribute(string fullyQualifiedAggregateName)
{
FullyQualifiedAggregateName = fullyQualifiedAggregateName;
}
}
The Domain.Core project references the source generator project.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Jaeger" Version="1.0.3" />
<PackageReference Include="OpenTracing.Contrib.NetCore" Version="0.9.0" />
<PackageReference Include="Scrutor" Version="4.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SourceGenerator.csproj" ReferenceOutputAssembly="false" PackAsAnalyzer="true" />
</ItemGroup>
</Project>
These projects are packed as nuget packages.
In my code I am using the marker attribute:
[EventApply("SampleAggregate.Sample")]
public class SampleAdded : DomainEvent
If I reference both packages:
<ItemGroup>
<PackageReference Include="Domain.Core" Version="3.0.43-beta" />
<PackageReference Include="SourceGenerator" Version="3.0.43-beta" />
</ItemGroup>
it works fine. But I would expect that I only need to reference Domain.Core as Domain.Core references the source generator.
What do I need to change that I don't need to reference the source generator itself?
I didn't find a possibility to that with project references. But it works find with package references. Here all it needs to create the nuget package.
Source generator csproj:
Using csproj (nuget package):