by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Yair Halberstadt
@YairHalberstadt
Try it and see what review says
CyrusNajmabadi
@CyrusNajmabadi
I think it would be accepted. We've done things like that before. Open an issue and ask Julien about it
Alireza Habibi
@alrz
will do. thanks
trampster
@trampster
How can I reference a local project from a Source Generator project, I want to be able to use code from a local project to help me do the generation.
I tried adding it as follows <ProjectReference Include="../JsonSGen/JsonSGen.csproj" />
But I get the following error when trying to use the Source Generator 'System.IO.FileNotFoundException: Could not load file or assembly 'JsonSGen, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Seems that the assembly is not getting copied to the location it runs from
stefanloerwald
@stefanloerwald
Try <ProjectReference Include="../JsonSGen/JsonSGen.csproj" OutputItemType="Analyzer" />
trampster
@trampster
No still the same error
stefanloerwald
@stefanloerwald
Do you use <LangVersion>preview</LangVersion> in both the generator and consumer project?
trampster
@trampster
Yes
stefanloerwald
@stefanloerwald
And are you sure your path is 100% correct?
trampster
@trampster
100%
stefanloerwald
@stefanloerwald
VS or CLI?
trampster
@trampster
vscode
so cli
on linux
stefanloerwald
@stefanloerwald
And you've got the right SDK installed too?
trampster
@trampster
Yes it was working fine until I tried to reference the local project
stefanloerwald
@stefanloerwald
What are the TargetFrameworks?
trampster
@trampster
Source Generator project is <TargetFramework>net5.0</TargetFramework>
Yair Halberstadt
@YairHalberstadt
I couldn't get this to work
trampster
@trampster
the referenced local project is <TargetFramework>netstandard2.1</TargetFramework>
Yair Halberstadt
@YairHalberstadt
Maybe create an issue on roslyn. I would like to know the answer.
trampster
@trampster
I've worked around it by referencing the indivdiual .cs files as links for now. I'll wait on raising an issue to see if I get an answer here.
I'm sure there must be a way ( or else I don't know how you could make a Source Generator of any significant complexity)
trampster
@trampster
(Also in my experience raising bugs on Microsoft projects is a waste of everyone's time, I've never had one fixed)
trampster
@trampster
(That's not a dig at Microsoft, they have a lot of bugs and noise to work through, lets just make sure its a real bug before raising it)
Yair Halberstadt
@YairHalberstadt
My bugs generally have been (depending on priority)
Raising it is always good, and they can triage it. This though is less of a bug, and more a good way of getting attention from someone who should know.
trampster
@trampster
Most projects don't like bugs reports that are really questions.
Yair Halberstadt
@YairHalberstadt
Roslyn is fine with them
IME
In Moderation
Antony Male
@canton7
I took the approach of referencing shared files as source
Yair Halberstadt
@YairHalberstadt
Can you do that from a project reference @canton7?
trampster
@trampster
I only needed the code from one file so have done <Compile Include="..\JsonSGen\StringBuilderExtension.cs" Link="StringBuilderExtension.cs" /> to get it as a link
But it's not ideal
Manish Vasani
@mavasani

How can I reference a local project from a Source Generator project, I want to be able to use code from a local project to help me do the generation.

Dependencies of analyzers/source generators must themselves be marked as Analyzer items in the project file.

CyrusNajmabadi
@CyrusNajmabadi
Also in my experience raising bugs on Microsoft projects is a waste of everyone's time, I've never had one fixed
Fwiw Roslyn has fixed thousands of issues reported there
For this case, I would just start a Roslyn discussion
Antony Male
@canton7
@YairHalberstadt I just did this, as the source generator and main library will never be loaded at once (except for unit tests, but I can handle that)
trampster
@trampster
@mavasni Do you mean I mark it as a Analyzer in the project reference, or in the actual project file, because the project itself cannot be marked as an Analyzer as it is used from normal .net projects as well
trampster
@trampster
@CyrusNajmabadi I'm not arguing that lots of bugs don't get fixed, Its just that Microsoft .net projects get so many bug reports that addressing them all in a timely manor is very hard for them, Roslyn has 7540 bugs currently open.
@CyrusNajmabadi How do I start a Roslyn discussion, the Issue list options are: Analyzer suggestion, Bug report, Report a security vulnerability and Suggest language feature.
trampster
@trampster
@CyrusNajmabadi Never mind, I see discussions are a separate tab.
trampster
@trampster
CyrusNajmabadi
@CyrusNajmabadi
Roslyn has 7540 bugs currently open.
And probably double that at least that are closed :-)