简体   繁体   中英

NuGet: Copying .DLL file without creating a reference?

I am working on my first open source project and now I want to create a NuGet from it so it is easy to use. In my project i'm using a DLL (CoolProp.dll) which is a third-party dll.

When running the program it needs to have the dll in:

..\bin\Release\CoolProp.dll

In the Solution Explorer (VS) I have set the CoolProp.dll to:

Build Action: None
Copy to Output Directory: Copy always

All this works as it should when just running the code.

In the .nuspec file I have added: (for it to copy the dll file)

<file src="bin\Release\CoolProp.dll" target="lib\net461" />

When installing the Nuget I get the followering error:

Failed to add reference to 'CoolProp'
Please make sure that the file is accessible, and that it is a valid assembly or COM component.

I am guessing it is trying to add a reference to the dll file, which its shouldn't do. It should just copy it and nothing else.

What am I doing wrong? or is there something I have misunderstood?

I finally got it to work!

My mistake was to put the dll in to the "lib\\net461" folder. As I understand it, putting it into that folder tell the system to make a reference to it.

Instead I did this:

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

Created a file name "SharpFluids.targets" and put this into it:

<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>

So now it just copies the dll file into output-folder without trying to create a reference to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM