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