-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generator stops generating code with multi-project solution #76
Comments
Why not just drop SYNC_METHOD_GENERATOR_DISABLE_ATTRIBUTE_GENERATION from project 3? Project 3 marks FooAsync with On my side |
What do you mean it is disabled for project 2? I didn't actively toggle it to do so. The whole point of disabling it in project 3 is because it conflicts with the generated attribute in project 2. A detail worth adding in is if I comment out the |
I see a mistake in Project 1 btw, but I think it should be obvious, it's not supposed to have a a ProjectReference, I'll update it |
Here is my configuration of your project. See how project 3 doesn't use Is that an acceptable solution? |
No not really, seems you just made InternalsVisible from Project1 to Project2 instead and that works for some bizarre reason. The problem is that where to use InternalsVisibleTo is a strategic decision, because otherwise you're leaking out implementation details wherever you're not supposed to. Usually InternalsVisibleTo are used on test projects which is safe because they're not distributed anywhere. In this example you can assume Project3 is a test project, and the other 2 are assembleis that are distributed to 3rd parties. Besides.. If anyone else run into this issue, how on earth are they supposed to figure out that they can solve it this way? It's not at all intuitive, and I'm pretty sure that once I start adding the analyzer to even more project in our 100+ projects big monolith, then this "solution" will not be so good anymore. I'm afraid the best workaround right now would be to simply not use the code generator at all for Project3. |
How about this now? This compiles fine for me |
Here you just removed the preprocessor directive from Project 3, which means it'll produce a compiler warning when it has 2 versions of the attribute to choose from. However the whole reason this preprocessor directive was introduced was because for solutions with warning as error it'll error. Add a Also a lot of devs doesn't want compiler warnings in their build, once you start allowing one, they tend to pile up I'm afraid the better solution is still to not use the code generator for the third project. |
This blog discusses how to solve attribute generation https://andrewlock.net/creating-a-source-generator-part-7-solving-the-source-generator-marker-attribute-problem-part1/ Right now this generator uses solution 1, but that has problems for us which is also discussed in the article. It seems we can get around the current problem by using solution 2, defining our own attribute and disabling the generator everywhere we use it appears to work. Hower it's a little tedious, and I think in the long run the generator would be best off implementing solution 3 as discussed in the blog. |
I think an obvious solution would be to allow a user define an additional macro. Currently we have: #if !SYNC_METHOD_GENERATOR_DISABLE_ATTRIBUTE_GENERATION If your csproj contains a line like <PropertyGroup>
<AdditionalSyncMethodGeneratorDisableAttributes>PROJ_2_DISABLE_ATTRIBUTE_GENERATION</AdditionalSyncMethodGeneratorDisableAttributes>
</PropertyGroup> The generated code would look like this: #if !SYNC_METHOD_GENERATOR_DISABLE_ATTRIBUTE_GENERATION && !PROJ_2_DISABLE_ATTRIBUTE_GENERATION ... or even better: the property could be named #if !PROJ_2_DISABLE_ATTRIBUTE_GENERATION What do you think? |
Actually that won't work since "RegisterPostInitializationOutput" only generates static string which has no access to the compilation object. |
This problem is a little complicated to setup but I think I was able to find a minimal reproduction, although I can't even begin to guess what could be wrong here. It specifically happens when using 3+ projects with
InternalsVisibleTo
andSYNC_METHOD_GENERATOR_DISABLE_ATTRIBUTE_GENERATION
. The code generator doesn't generate any code in Project 3, there's no Foo3(). It happens completely silently and I have to try and reference the method or add it as a interface contract to force a build error.Project 1
Project 2
Project 3
The text was updated successfully, but these errors were encountered: