11

我在 nuget 包的 init.ps1 中遇到 ps 脚本问题。我试图在安装包时创建一个解决方案文件夹,然后将 dlls/pdbs 复制到这个文件夹(并删除项目中包安装的源 dll/pdbs)。我能够创建解决方案文件夹,但无法将文件从 \content\temp 目录复制到解决方案文件夹。事实上,我真的想要文件系统上的真实文件夹和解决方案文件夹匹配,所以副本应该将文件复制到真实文件系统文件夹,然后添加到解决方案文件夹。
复制部分不起作用,我没有收到任何输出错误。有点丢了。

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
4

1 回答 1

10

我遇到了同样的问题,并在 BuildDeploySupport 项目中找到了一个 PowerShell 脚本,它正是这样做的。您需要做的就是在几个地方更新您要复制的文件夹的名称(下面链接的 ps1 中的 Deploy\Support)。

请参阅BuildDeploySupport 解决方案文件夹复制 Init.ps1

来自链接(截至 2017 年 11 月 30 日):

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
于 2014-03-17T14:59:06.523 回答