[英]Unable to add native .dll reference to source generator project
You can find the full source code at https://github.com/myblindy/GrimBuilding/tree/efcore (the efcore
branch).你可以找到完整的源代码https://github.com/myblindy/GrimBuilding/tree/efcore (在
efcore
分支)。
I understand that source generators can't automatically harvest dependencies from nuget packages and you have to use a clunky work-around to get it to work, and I have done so.我知道源代码生成器无法自动从 nuget 包中获取依赖项,您必须使用笨拙的解决方法才能使其工作,而我已经这样做了。 This is my source generator project:
这是我的源代码生成器项目:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.0-1.final" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" PrivateAssets="all" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.*-*" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="6.*-*" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="2.*-*" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="SQLitePCLRaw.provider.e_sqlite3" Version="2.*-*" GeneratePathProperty="true" PrivateAssets="all" />
</ItemGroup>
<PropertyGroup>
<GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn>
</PropertyGroup>
<Target Name="GetDependencyTargetPaths">
<ItemGroup>
<TargetPathWithTargetPlatformMoniker Include="$(PKGSQLitePCLRaw_bundle_e_sqlite3)\lib\netstandard2.0\SQLitePCLRaw.batteries_v2.dll" IncludeRuntimeDependency="false" />
<TargetPathWithTargetPlatformMoniker Include="$(PKGSQLitePCLRaw_provider_e_sqlite3)\lib\netstandard2.0\SQLitePCLRaw.provider.e_sqlite3.dll" IncludeRuntimeDependency="false" />
<TargetPathWithTargetPlatformMoniker Include="$(PKGSQLitePCLRaw_lib_e_sqlite3)\runtimes\win-x64\native\e_sqlite3.dll" IncludeRuntimeDependency="false" />
<TargetPathWithTargetPlatformMoniker Include="$(PKGMicrosoft_Data_Sqlite_Core)\lib\netstandard2.0\Microsoft.Data.Sqlite.dll" IncludeRuntimeDependency="false" />
</ItemGroup>
</Target>
</Project>
Since there also isn't any transitive support, I added every nested Microsoft.Data.Sqlite
package one by one, generated their path property and referenced it using TargetPathWithTargetPlatformMoniker
.由于也没有任何传递支持,我将每个嵌套的
Microsoft.Data.Sqlite
包一一添加,生成它们的路径属性并使用TargetPathWithTargetPlatformMoniker
引用它。 It all works until I get to the native e_sqlite3.dll
, if I use TargetPathWithTargetPlatformMoniker
with it, it tries to reference it as a managed library, and it fails as expected:这一切都有效,直到我到达本机
e_sqlite3.dll
,如果我将TargetPathWithTargetPlatformMoniker
与它一起使用,它会尝试将其作为托管库引用,但它会按预期失败:
4>CSC : warning CS8034: Unable to load Analyzer assembly C:\Users\meep\.nuget\packages\sqlitepclraw.lib.e_sqlite3\2.0.5-pre20210521085756\runtimes\win-x64\native\e_sqlite3.dll : PE image doesn't contain managed metadata.
So given that the path is found, is there a different tag I can use to make the main project copy the e_sqlite3.dll
file so the analyzer can use it?因此,鉴于找到了路径,是否可以使用不同的标记来使主项目复制
e_sqlite3.dll
文件,以便分析器可以使用它?
Taken from .NET project SDK overview :摘自.NET 项目 SDK 概述:
Build events构建事件
In SDK-style projects, use an MSBuild target named PreBuild or PostBuild and set the BeforeTargets property for PreBuild or the AfterTargets property for PostBuild.在 SDK 样式的项目中,使用名为 PreBuild 或 PostBuild 的 MSBuild 目标,并为 PreBuild 设置 BeforeTargets 属性或为 PostBuild 设置 AfterTargets 属性。
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command=""$(ProjectDir)PreBuildEvent.bat" "$(ProjectDir)..\" "$(ProjectDir)" "$(TargetDir)"" />
</Target>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="echo Output written to $(TargetDir)" />
</Target>
Maybe you can move the file manually using one of these directives?也许您可以使用这些指令之一手动移动文件?
There's also this:还有这个:
<Content Include="$(OutputPath)\*.dll;$(OutputPath)\*.json">
<Pack>true</Pack>
<PackagePath>build\</PackagePath>
</Content>
Could you move the file like that?你能像那样移动文件吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.