我是 Nuget 的新手,我正在尝试上传我的第一个包。到目前为止,一切都很顺利。但是,我试图在一些我想放在 Lib 子文件夹中的内容文件上设置 CopyToOutputDirectory。我的目录如下所示:
│ Readme.txt
│ MyPackage.nupkg
│ MyPackage.nuspec
│
├───content
│ └───Lib
│ native1.dll
│ native2.dll
│ native3.dll
│ native4.dll
│
├───lib
│ MyActualAssembly.dll
│
└───tools
Install.ps1
通过阅读这个 StackOverflow 问题和一些额外的阅读,我整理了一个如下所示的 Install.ps1:
param($installPath, $toolsPath, $package, $project)
$project.ProjectItems.Item("Lib\native1.dll").Properties.Item("CopyToOutputDirectory").Value = 1
$project.ProjectItems.Item("Lib\native2.dll").Properties.Item("CopyToOutputDirectory").Value = 1
$project.ProjectItems.Item("Lib\native3.dll").Properties.Item("CopyToOutputDirectory").Value = 1
$project.ProjectItems.Item("Lib\native4.dll").Properties.Item("CopyToOutputDirectory").Value = 1
我对各种操作进行了 1 排列,以查看它是否有助于我理解问题,但实际上与其他答案相同。
根据我的测试,Install.ps1 在查找文件本身时遇到了一些麻烦。安装软件包后运行时,出现以下错误:
Exception calling "Item" with "1" argument(s): "The parameter is incorrect. (Exception from HRESULT: 0x80070057
(E_INVALIDARG))"
At C:\...\tools\Install.ps1:3 char:1
+ $project.ProjectItems.Item("Lib\native1.dll").Properties.Item("CopyToOutputDirect ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation
Exception calling "Item" with "1" argument(s): "The parameter is incorrect. (Exception from HRESULT: 0x80070057
(E_INVALIDARG))"
At C:\...\tools\Install.ps1:4 char:1
+ $project.ProjectItems.Item("Lib\native2.dll").Properties.Item("Copy ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation
Exception calling "Item" with "1" argument(s): "The parameter is incorrect. (Exception from HRESULT: 0x80070057
(E_INVALIDARG))"
At C:\...\tools\Install.ps1:5 char:1
+ $project.ProjectItems.Item("Lib\native3.dll").Properties.Item("CopyToOutputDirec ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation
Exception calling "Item" with "1" argument(s): "The parameter is incorrect. (Exception from HRESULT: 0x80070057
(E_INVALIDARG))"
At C:\...\tools\Install.ps1:6 char:1
+ $project.ProjectItems.Item("Lib\native4.dll").Properties.Item("CopyToOut ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation
而且,正如您所料,所有文件的 CopyToOutputDirectory 设置都设置为“不复制”,这是默认设置。
我该如何解决这个问题?访问 ps 脚本中的子文件夹是否有不同的语法?还是我完全错过了这些错误消息的重点?