NuGet:复制.DLL文件而不创建引用?

问题描述 投票:2回答:1

我正在处理我的第一个open source project,现在我想从中使用create a NuGet,所以它很容易使用。在我的项目中,我正在使用一个DLL(CoolProp.dll),它是第三方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文件的引用,但不应这样做。它应该只复制它,别无其他。

我在做什么错?还是我误解了?

c# nuget nuget-package
1个回答
0
投票

我终于让它工作了!

我的错误是将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文件复制到输出文件夹中,而无需尝试创建对该文件的引用。

© www.soinside.com 2019 - 2024. All rights reserved.