2013-03-17 27 views
7

我是新來的Nuget,我試圖找出上傳我的第一個包。到目前爲止,一切都很順利。但是,我試圖設置CopyToOutputDirectory的一些內容文件,我想住在Lib子文件夾中。我的目錄看起來是這樣的:Nuget - 在子文件夾中的內容上設置CopyToOutputDirectory

│ Readme.txt 
│ MyPackage.nupkg 
│ MyPackage.nuspec 
│ 
├───content 
│ └───Lib 
│   native1.dll 
│   native2.dll 
│   native3.dll 
│   native4.dll 
│ 
├───lib 
│  MyActualAssembly.dll 
│ 
└───tools 
     Install.ps1 

從閱讀this StackOverflow question和一些額外的閱讀,我已經把一個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 

I 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腳本中的子文件夾?還是我完全錯過了這些錯誤消息的重點?

回答

10

嘗試,而不是執行以下操作:

$project.ProjectItems.Item("Lib").ProjectItems.Item("native1.dll").Properties.Item("CopyToOutputDirectory").Value = 1 

我可能是錯了,但我不認爲ProjectItems將讓你找到不屬於當前項目的直接子項。所以你需要先找到Lib文件夾項目,然後在你的dll中查看這個項目項目。

爲了測試這些我平時開的包管理器控制檯窗口中,確保正確的項目在默認的項目選擇下拉列表,然後通過使用命令行訪問項目對象:

$項目= Get-Project

這給你和NuGet安裝腳本一樣,它是項目的Visual Studio對象模型。

+0

對不起,最後的評論,我剛剛重讀你的答案,我錯過了第一個位置,你先得到了Lib,然後是dll。從使用get-project想法在PM控制檯中播放,它看起來是正確的。我現在就試試吧! – 2013-03-18 18:34:15

+0

賓果! Visual Studio錯誤地告訴我腳本執行被禁用後,我重新啓動,現在導入運行順利,文件的屬性正確設置。謝謝。 – 2013-03-18 19:12:35

相關問題