2013-09-27 239 views
9

Tôi gặp sự cố với tập lệnh ps trong init.ps1 gói nuget. Tôi đang cố gắng để tạo ra một thư mục giải pháp sau khi cài đặt gói và sau đó sao chép dlls/pdbs vào thư mục này (và xóa các dll nguồn/pdbs được cài đặt bởi các gói trong dự án). Tôi có thể tạo thư mục giải pháp nhưng gặp sự cố khi sao chép các tệp từ thư mục \ content \ temp vào thư mục giải pháp. Trong thực tế, tôi thực sự muốn một thư mục thực sự trên hệ thống tập tin và thư mục giải pháp để phù hợp, vì vậy bản sao nên sao chép các tập tin vào thư mục hệ thống tập tin thực và sau đó được thêm vào thư mục giải pháp.
Phần bản sao không hoạt động và tôi không nhận được bất kỳ lỗi đầu ra nào. Mất chút.Sao chép tệp vào thư mục giải pháp với init.ps1 và 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

Ra quan tâm, những con đường bạn đang đi đến $ installpath và $ toolsPath – mitchimus

+0

@mitchimus đây là những gì đường dẫn được truyền qua môi trường NuGet Powershell và tương ứng với đường dẫn tuyệt đối nơi gói được cài đặt (thư mục trong thư mục "gói", nằm trong cùng thư mục với tệp giải pháp) và đường dẫn đến thư mục "tools" trong $ installPath, tương ứng. – ygormutti

Trả lời

7

Tôi gặp sự cố tương tự và tìm thấy tập lệnh PowerShell trong dự án BuildDeploySupport đã thực hiện chính xác việc này. Tất cả những gì bạn cần làm là cập nhật tên thư mục bạn muốn sao chép (Deploy \ Support trong ps1 được liên kết bên dưới) ở một vài nơi.

Xem BuildDeploySupport Solution Folder Copy Init.ps1

Từ liên kết (tính đến 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

Chỉ ra rằng tập lệnh không đệ quy, nhưng làm cho tập lệnh trở nên dễ dàng. Sửa đổi dòng 36 để đọc: 'ls -recurse $ deployTarget | foreach-object {' – mshish

+3

Vui lòng sao chép trong các phần có liên quan (để lại liên kết dưới dạng ghi nhận tác giả). Các trang web đã được biết là biến mất và thậm chí thay đổi theo thời gian. – Crisfole