我是 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 问题 https://stackoverflow.com/questions/8474253/nuget-how-can-i-change-property-of-files-with-install-ps1-file和一些额外的阅读,我整理了一个 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
我排列了各种操作,看看它是否有助于我理解问题,但它实际上与其他答案相同。
根据我的测试,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 脚本中的子文件夹是否有不同的语法?或者我完全没有理解这些错误消息的要点吗?