You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use the source generator to generate typescript files for several C# class libraries. I wanted to have a shared config, so I created a simple BaseConfig class in a different library project that will be shared with the others.
using NTypewriter.Editor.Config;namespace MySharedLib;publicclassBaseConfig:EditorConfig{publicoverrideboolAddGeneratedFilesToVSProject=>false;// etc.}
Then, in one of those projects, I created the project config (ProjConfig.nt.cs) that inherits from the BaseConfig like so:
using MySharedLib;using System.Collections.Generic;namespace Proj1.NTypewriter;publicclassProjConfig:BaseConfig{publicoverrideIEnumerable<string> NamespacesToBeSearched {get{yieldreturn"Proj1.Dtos";yieldreturn"Proj1.Controllers";}}}
This all compiles fine, but when the source generator runs, it says it can't find MySharedLib.
Does the source generator not share the same dependencies as the project it's running on? Is there some way to configure this? Hoping I'm just missing something obvious. 😅
Also, on a sidenote, using System.Collections.Generic; is also required even though the editor says it's not needed and can be removed.
The text was updated successfully, but these errors were encountered:
A source generator, in general, is run in the context of a given project, it does not know anything about other projects in the solution, nor does it have access to source files from other projects. A source generator is run as a part of a compilation, it shares dependencies with the compiler (VS/MsBuild/dotnet build), not with the project that is compiled.
So, the only way to share base config file between projects is by linking that file to the projects.
Thanks for the tip! I managed to get the BaseConfig compiling by adding it as a linked file and ensuring it had a .nt.cs extension (I originally just had .cs and it was giving the same error as before saying it couldn't find it). Not the best, but it's working. 👍
I'm trying to use the source generator to generate typescript files for several C# class libraries. I wanted to have a shared config, so I created a simple
BaseConfig
class in a different library project that will be shared with the others.Then, in one of those projects, I created the project config (
ProjConfig.nt.cs
) that inherits from theBaseConfig
like so:This all compiles fine, but when the source generator runs, it says it can't find
MySharedLib
.Does the source generator not share the same dependencies as the project it's running on? Is there some way to configure this? Hoping I'm just missing something obvious. 😅
Also, on a sidenote,
using System.Collections.Generic;
is also required even though the editor says it's not needed and can be removed.The text was updated successfully, but these errors were encountered: