Closed KondzioSSJ4 closed 1 year ago
Walkaround...
Instead of using x.NamespaceNames.FirstOrDefault() == DependantProjectName
use: x.Identity.Name.StartsWith(DependantProjectName)
for that single operation
but still... the same operation against test/build/vs should return the same results
@chsienki fyi
I don't understand why this is expected to work:
.Where(x => x.NamespaceNames.FirstOrDefault() == DependantProjectName)
Assemblies have multiple namespaces, including namespaces that are implicitly added by project system tools. I don't see any documentation suggesting that the order of namespaces in this collection would require any specific item to appear first.
@sharwell Ok, but it's strange that only doesn't work in Roslyn process and everywhere else is fine
Also... as far as I remember that x.NamespaceNames.Select(x => x.ToString())
returns different results in Roslyn than it returning in other ways
and I think that was a problem for me
(that ticket stay for one month... so it's harder to remember details)
I recently found that ProjectReference assembly is not copied in AnalyzerAssemblyLoader folder when CodeGenerator is preparing for run. In C:\Users\Alexei\AppData\Local\Temp\VS\AnalyzerAssemblyLoader\*\*\
directories, each directory has only one assembly and CodeGenerators with project references cannot start. I use Version 17.0.5 of vs
I recently found that ProjectReference assembly is not copied in AnalyzerAssemblyLoader folder when CodeGenerator is preparing for run.
This is correct by default. You have to modify the project logic to itemize all necessary assemblies as part of GetTargetPathDependsOn
. Here's an example involving both ProjectReference and PackageReference:
Thanks, but when I can read about it? (Except microsoft employee repositories, they made it and know how it works 🤣 )
This is not covered by docs here: https://github.com/dotnet/roslyn/blob/main/docs/features/source-generators.cookbook.md https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview
I don't believe there's any documentation of this at this time. We'd like to make it more convenient, but so far have not completed that work.
Version Used:
Visual Studio 17.0.1 (newest) Microsoft.CodeAnalysis.CSharp.Workspaces 3.11.0
Steps to Reproduce:
BaseProject
AppProject
BaseProject
to projectAppProject
as a project referenceSourceGenerator
project that generates code depending on reference project (code provided below)AppProject
AppProject
theConsole.Write
of variableGeneratedCode.SymbolsInfo.SymbolCount
(generated)1
(that's correct behavior)0
(not expected!) (process what want to run this generator and return invalid result:ServiceHub.RoslynCodeAnalysisService.exe
)If you try to build a project with turn-on debugger, you also get
1
as a result ofsymbol.Count
I also created test, but the result is also1
(correct)Code for Source Generator:
Expected Behavior: That source generator will works the same in:
ServiceHub.RoslynCodeAnalysisService.exe
)Actual Behavior: Roslyn when building SourceGenerator not include dependency projects before build
That error doesn't look scary, but because of this error, there isn't any possible way to create more advanced source generators in a normal live scenario, because currently most of the projects are separated by many
csproj
(for example to separate layers). e.g. You never saw project with CQRS and with query/commands and API controllers in the samecsproj