gpt4 book ai didi

c# - NuGet:在不创建引用的情况下复制 .DLL 文件?

转载 作者:行者123 更新时间:2023-12-04 15:35:52 24 4
gpt4 key购买 nike

我正在做我的第一个 open source project现在我想create a NuGet从它所以很容易使用。
在我的项目中,我使用的是第三方 dll 的 DLL (CoolProp.dll)。

运行程序时,它需要将 dll 放在:

..\bin\Release\CoolProp.dll

在解决方案资源管理器 (VS) 中,我将 CoolProp.dll 设置为:
Build Action: None
Copy to Output Directory: Copy always

所有这些都在运行代码时正常工作。

在我添加的 .nuspec 文件中:(为了它复制 dll 文件)
<file src="bin\Release\CoolProp.dll" target="lib\net461" />

安装 Nuget 时出现以下错误:
Failed to add reference to 'CoolProp'
Please make sure that the file is accessible, and that it is a valid assembly or COM component.

我猜它正在尝试添加对 dll 文件的引用,这是它不应该做的。它应该只是复制它而不是其他任何东西。

我究竟做错了什么?或者我有什么误解?

最佳答案

我终于让它工作了!

我的错误是将 dll 放入“lib\net461”文件夹中。
据我了解,将其放入该文件夹会告诉系统对其进行引用。

相反,我这样做了:

<file src="..\CoolProp.dll" target="build\" />
<file src="..\SharpFluids.targets" target="build\" />

创建一个文件名“SharpFluids.targets”并将其放入其中:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<NativeLibs Include="$(MSBuildThisFileDirectory)**\*.dll" />
<None Include="@(NativeLibs)">
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

所以现在它只是将 dll 文件复制到输出文件夹中,而不尝试创建对它的引用。

关于c# - NuGet:在不创建引用的情况下复制 .DLL 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59787794/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com