2013-09-27 71 views
9

我在使用nuget包的init.ps1中的ps腳本時遇到問題。我試圖創建一個解決方案文件夾安裝包然後將dlls/pdbs複製到此文件夾(並刪除項目中的包安裝的源dll/pdbs)。 我能夠創建解決方案文件夾,但是無法將文件從\ content \ temp目錄複製到解決方案文件夾。 實際上,我真的想要一個文件系統上的實際文件夾和一個解決方案文件夾相匹配,所以副本應該將這些文件複製到真實的文件系統文件夾中,然後將其添加到解決方案文件夾中。
複製部分不起作用,我沒有收到任何輸出錯誤。位丟失。使用init.ps1和nuget將文件複製到解決方案文件夾

param($installPath, $toolsPath, $package, $project) 

# Get the open solution. 
$solution = Get-Interface $dte.Solution ([EnvDTE80.Solution2]) 

# Create the parent solution folder. 
$parentProject = $solution.AddSolutionFolder("MyDlls") 

# Create a child solution folder. 
$parentSolutionFolder = Get-Interface $parentProject.Object ([EnvDTE80.SolutionFolder]) 

$fileName = (Join-Path $installPath "\temp\mydll") 
$projectFile = $parentSolutionFolder.AddFromFile($fileName) 

Write-Host "" 
Write-Host $sourcePath 
Write-Host $parentSolutionFolder 
+0

出於興趣,什麼是你傳遞到$ INSTALLPATH的路徑和$ toolsPath – mitchimus

+0

@mitchimus這些路徑由NuGet Powershell環境傳遞,並對應於安裝軟件包的絕對路徑(與「解決方案文件」位於同一目錄下的「軟件包」目錄中的目錄)以及$中「tools」文件夾的路徑installPath,分別。 – ygormutti

回答

7

我遇到了同樣的問題,在BuildDeploySupport項目中發現了一個PowerShell腳本,它完成了這個工作。您只需在幾個地方更新您想要複製的文件夾的名稱(在下面鏈接的ps1中部署\支持)。

BuildDeploySupport Solution Folder Copy Init.ps1

從鏈路(截至30/11/2017):

param($installPath, $toolsPath, $package) 

# find out where to put the files, we're going to create a deploy directory 
# at the same level as the solution. 

$rootDir = (Get-Item $installPath).parent.parent.fullname 
$deployTarget = "$rootDir\Deploy\Support\" 

# create our deploy support directory if it doesn't exist yet 

$deploySource = join-path $installPath 'tools/deploy' 

if (!(test-path $deployTarget)) { 
    mkdir $deployTarget 
} 

# copy everything in there 

Copy-Item "$deploySource/*" $deployTarget -Recurse -Force 

# get the active solution 
$solution = Get-Interface $dte.Solution ([EnvDTE80.Solution2]) 

# create a deploy solution folder if it doesn't exist 

$deployFolder = $solution.Projects | where-object { $_.ProjectName -eq "Deploy" } | select -first 1 

if(!$deployFolder) { 
    $deployFolder = $solution.AddSolutionFolder("Deploy") 
} 

# add all our support deploy scripts to our Support solution folder 

$folderItems = Get-Interface $deployFolder.ProjectItems ([EnvDTE.ProjectItems]) 

ls $deployTarget | foreach-object { 
    $folderItems.AddFromFile($_.FullName) > $null 
} > $null 
+1

原來,腳本不是遞歸的,但使其遞歸很容易。修改第36行以讀取:'ls -recurse $ deployTarget | foreach-object {' – mshish

+3

請複製相關內容(將鏈接留爲歸屬地)。據瞭解,網站會隨着時間消失甚至發生變化。 – Crisfole

相關問題