无法访问包含的文件sourcegenerator

发布于 2025-01-26 03:03:43 字数 858 浏览 4 评论 0原文

我将此项目组添加到sourcegenerator.csproj文件

<ItemGroup>
        <Content Include="defs\*\*.json" CopyToOutputDirectory="PreserveNewest" />
        <Content Include="Templates\*.template" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

obs:如果我构建sourcegenerator项目,则将文件复制到输出。

我会得到这样的模板文件的路径:

var path = Path.Combine(AppContext.BaseDirectory, "Templates", _fileName);

但是,在试图编译引用此Sourcecode生成器的项目时,我会收到警告:

Generator 'SourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'DirectoryNotFoundException' with message 'Could not find a part of the path 'C:\Program Files\dotnet\sdk\6.0.300-preview.22204.3\Roslyn\bincore\Templates\Struct.template'.'

I added this ItemGroup to the SourceGenerator.csproj file

<ItemGroup>
        <Content Include="defs\*\*.json" CopyToOutputDirectory="PreserveNewest" />
        <Content Include="Templates\*.template" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

OBS: The files get copied to the output if i build the SourceGenerator project.

I get the path of the template file like this:

var path = Path.Combine(AppContext.BaseDirectory, "Templates", _fileName);

But, while trying to compile the Project that references this SourceCode generator i get an warning:

Generator 'SourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'DirectoryNotFoundException' with message 'Could not find a part of the path 'C:\Program Files\dotnet\sdk\6.0.300-preview.22204.3\Roslyn\bincore\Templates\Struct.template'.'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文