使用init.ps1和nuget将文件复制到解决方案文件夹

11

我在NuGet包的init.ps1脚本中遇到了问题。我尝试在安装包时创建一个解决方案文件夹,然后将dll / pdb复制到此文件夹中(并删除项目中由包安装的源dll / pdb)。 我成功创建了解决方案文件夹,但无法将文件从\ 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

出于兴趣,你传递给$installPath和$toolsPath的路径是什么? - mitchimus
@mitchimus 这些路径是由NuGet Powershell环境传递的,并且分别对应于程序包安装的绝对路径(位于“packages”目录中的目录,与解决方案文件所在的同一目录)和$installPath中“tools”文件夹的路径。 - ygormutti
1个回答

10
我曾经遇到同样的问题,后来在BuildDeploySupport项目中找到了一个PowerShell脚本,可以完美地解决这个问题。你只需要在多处更新ps1文件中要复制的文件夹名称(Deploy\Support),就可以了。
参考链接:BuildDeploySupport Solution Folder Copy 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

1
原来那个脚本不是递归的,但是让它变成递归的很容易。将第36行修改为:ls -recurse $deployTarget | foreach-object { - mshish
3
请在相关部分复制(保留链接作为归属)。网站被人所知的是可能会消失甚至随时间改变。 - Chris Pfohl

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接