使用init.ps1和nuget将文件复制到solution文件夹

时间:2021-12-17 00:36:25

I am having trouble with ps script in init.ps1 of nuget package. I am trying to create a solution folder upon install of the package AND then copy dlls/pdbs to this folder (and delete the source dll/pdbs installed by the package in the project). I am able to create the solution folder, but am having trouble copying the files from the \content\temp directory to the solution folder. In fact, i really want a real folder on the filesystem and a solution folder to match, so the copy should copy the files to the real file system folder and then be added to the solution folder.
The copy portion is not working and I am not getting any output errors. Bit lost.

我在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

1 个解决方案

#1


8  

I had the same issue and found a PowerShell script in the BuildDeploySupport project that did exactly this. All you need to do is update the name of the folder you'd like to copy in (Deploy\Support in the ps1 linked below) in several places.

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

See BuildDeploySupport Solution Folder Copy Init.ps1

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

From link (as of 30/11/2017):

来自链接(截至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


8  

I had the same issue and found a PowerShell script in the BuildDeploySupport project that did exactly this. All you need to do is update the name of the folder you'd like to copy in (Deploy\Support in the ps1 linked below) in several places.

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

See BuildDeploySupport Solution Folder Copy Init.ps1

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

From link (as of 30/11/2017):

来自链接(截至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