簡體   English   中英

DLL 在 NuGet package 沒有出現在構建 Z78E6221F6393D1356681DB398ZCE 文件夾中

[英]DLL in NuGet package not appearing in build output folder

我們有一個 NuGet package 由我們自己創建並托管在內部存儲庫上。 我們已經在 a.Net Framework 4.x 解決方案中使用了幾年。 package 包含一個 .Net4.x 程序集(一個 class 庫,由解決方案中的代碼引用)、兩個“本機”DLL 和一些 .Z4A8A08F09D37B73795349038408B 文件當解決方案構建時,package 中的每個文件都被復制到構建 output 文件夾中,這是我們所期望的。

我現在已將此解決方案遷移到 .Net6 並引用相同的 package,但構建行為不同。 在這里,解決方案構建成功,但 package 中的所有文件都沒有復制到構建 output 文件夾中。 相反,兩個本機 DLL 和 .c 文件被復制到引用項目的根文件夾(也顯示在 VS 解決方案資源管理器窗口中)。 .Net 程序集 (TspAdqAcquisition.dll) 不會出現在項目根文件夾或其他任何地方。

這是怎么回事?

這是 nuspec 文件(來自 Tsp...dll 和其他文件所在的“庫”解決方案):

<?xml version="1.0" encoding="utf-8"?>
<package >
  <metadata minClientVersion="2.5">
    ....
  </metadata>

  <files>    
    <file src="x64\Release\*.c" target="build" />
    <file src="x64\Release\glew64.dll" target="build\glew64.dll" />
    <file src="x64\Release\glut64.dll" target="build\glut64.dll" />
    <file src="x64\Release\TspAdqAcquisition.dll" target="lib\net451\TspAdqAcquisition.dll" />
    <file src="x64\Release\TspAdqAcquisition.dll" target="lib\net\TspAdqAcquisition.dll" />
    <file src="x64\Release\TspAdqAcquisition.dll" target="lib\net6.0\TspAdqAcquisition.dll" />
    <file src="x64\Release\TspAdqAcquisition.dll" target="lib\net6.0-windows10\TspAdqAcquisition.dll" />
    <file src="x64\Release\TspAdqAcquisition.dll" target="lib\net6.0-windows11\TspAdqAcquisition.dll" />
  </files>
</package>

編輯我已經弄清楚為什么兩個本機 DLL 和 .c 文件沒有被復制到構建 output 文件夾中。 The NuGet package in question is referenced by a class library project (net6.0 TFM rather than net6.0-windows), so these particular files were ending up in a separate \net6.0\ build output folder, rather than the \net6 .0-windows\ build output folder that the rest of the solution ends up in. Once I'd referenced that class library project by one of the WPF projects, these files appeared in the correct build output folder.

但是,TspAdqAcquisition.dll 程序集仍然沒有被復制到(或者)構建 output 文件夾。

編輯 2我現在可以通過在項目文件中包含以下行來獲取 TspAdqAcquisition.dll 程序集以復制到構建 output 文件夾:

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

我必須將它放在WPF 項目文件中,以確保將 DLL 復制到正確的 (\net6.0-windows) 構建 output 文件夾中。 If I add the above line to the class library project file referencing the NuGet package then the DLL ends up in the wrong (\net6.0) build output folder.

對於我的喜好,這一切都開始變得有點駭人聽聞了……

我剩下的最后一個問題是,是否有可能阻止那些本機 DLL 和 .c 文件被“解包”到項目文件夾中並弄亂解決方案資源管理器 window? 為什么在 VS2019 中不會發生這種情況?

看來您在 nuget package 中沒有 .targets 文件。 我不確定這是否應該是“正常”的方式,但這就是我將本機二進制文件復制到 output 的方式。

因此,使其正常工作的一種可能方法是在 nuget 的build文件夾中創建一個<packagename>.targets文件,其內容如下:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="CopyFilesToTargetDirectory_MyPackageName" BeforeTargets="Build">
    <ItemGroup>
            <FilesForTargetDirectory_MyPackageName Include="$(MSBuildThisFileDirectory)\..\tools\**\*.*" />
    </ItemGroup>
    <PropertyGroup>
            <TargetDirectory_MyPackageName Condition="'$(TargetDirectory_MyPackageName)' == ''">$(TargetDir)</TargetDirectory_MyPackageName>
    </PropertyGroup>
    <Copy SourceFiles="@(FilesForTargetDirectory_MyPackageName)" 
          DestinationFolder="$(TargetDirectory_MyPackageName)\%(RecursiveDir)"
          SkipUnchangedFiles="true" />
  </Target>
</Project>

然后,將本地庫從build文件夾移動到tools文件夾(如上面的示例代碼中)或lib\native文件夾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM