Skip to content

Reference local projects in Source Generator #47517

Answered by sharwell
trampster asked this question in General
Discussion options

You must be logged in to vote

You can add a dependency to a source generator in the same solution through three steps:

  1. Add a <PackageReference>, making sure to set both GeneratePathProperty="true" and PrivateAssets="all"
  2. Add a build target to add <TargetPathWithTargetPlatformMoniker> elements as part of GetTargetPath, and add all the required dependency assemblies inside this target, making sure to set IncludeRuntimeDependency="false"
  3. Update <GetTargetPathDependsOn> to ensure the target from the previous step is used

You can see an example of these steps here:
https://github.com/dotnet/roslyn-sdk/blob/0313c80ed950ac4f4eef11bb2e1c6d1009b328c4/samples/CSharp/SourceGenerators/SourceGeneratorSamples/SourceGeneratorSampl…

Replies: 15 comments 59 replies

Comment options

You must be logged in to vote
1 reply
@canton7
Comment options

Comment options

You must be logged in to vote
0 replies

This comment has been hidden.

Comment options

You must be logged in to vote
1 reply
@trampster
Comment options

Comment options

You must be logged in to vote
5 replies
@trampster
Comment options

@mavasani
Comment options

@sharwell
Comment options

sharwell Sep 8, 2020
Collaborator

@jasonmalinowski
Comment options

@Eli-Black-Work
Comment options

Comment options

You must be logged in to vote
31 replies
@Eli-Black-Work
Comment options

@trungnt2910
Comment options

@trungnt2910
Comment options

@Eli-Black-Work
Comment options

@trungnt2910
Comment options

Answer selected by jmarolf
Comment options

You must be logged in to vote
1 reply
@xyven1
Comment options

Comment options

You must be logged in to vote
4 replies
@ganeshnj
Comment options

@sven-n
Comment options

@erwan-joly
Comment options

Comment options

You must be logged in to vote
2 replies
@ptasev
Comment options

@ViRuSTriNiTy
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@devantler
Comment options

@farid-fereidooni
Comment options

@seclerp
Comment options

@CostaBru
Comment options

@znakeeye
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Eli-Black-Work
Comment options

Comment options

You must be logged in to vote
7 replies
@MeltyPlayer
Comment options

@devantler
Comment options

@MeltyPlayer
Comment options

@vpenades
Comment options

@aspeckt-112
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet