Nuget复制文件并将其添加到解决方案级别 [英] Nuget copy and add files to solution level

查看:69
本文介绍了Nuget复制文件并将其添加到解决方案级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个NUGET包,该包将多个文件添加到某个解决方案文件夹中.具体来说,该软件包必须在安装时执行以下操作:

  1. 在目标项目中创建一个临时文件夹.
  2. 将所有与扩展名匹配的文件(例如* .txt)复制到temp文件夹中.
  3. 将文件移动到解决方案根目录.
  4. 创建一个名为解决方案项目"的解决方案文件夹.
  5. 添加所有刚刚移到该解决方案文件夹的文件.
  6. 两者解决方案和磁盘中删除临时文件夹.

我使用 package.nuspec 文件创建一个临时目录并转储文件,然后使用 init.ps1 进行其余操作.

不幸的是,在第1步之后没有任何反应.


这是我的 package.nuspec 文件.

 <?xml version ="1.0"?>< package xmlns ="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"><元数据>< id> IncludeFiles</id>< version> 1.0</version>< authors> Chameera</authors>< owners> Chameera</owners>< requireLicenseAcceptance> false</requireLicenseAcceptance>< description>虚拟包含文件</description><标签>虚拟</标签></元数据><文件>< file src ="source \ *.txt" target ="content \ temp"/></files></package> 


这是我的 init.ps1 文件.

  param($ installPath,$ toolsPath,$ package,$ project)$ projectFullName = $ project.FullName$ fileInfo =新对象-typename System.IO.FileInfo -ArgumentList $ projectFullName$ projectDirectory = $ fileInfo.DirectoryName$ tempDirectory =临时"$ sourceDirectory ="$ projectDirectory \ $ tempDirectory"$ destinationDirectory =(获取项目$ sourceDirectory).parent.FullNameif(测试路径$ sourceDirectory -pathtype容器){robocopy $ sourceDirectory $ destinationDirectory/XO$ tempDirectoryProjectItem = $ project.ProjectItems.Item($ tempDirectory)$ tempDirectoryProjectItem.Remove()删除项目$ sourceDirectory -recurse} 

解决方案

在nuget软件包浏览器中使用nuspec打开创建的软件包时,您在content \ temp文件夹中看到任何.txt文件吗?/p>

调用nuget.exe包时,它将在制作包本身的同时将.txt文件从源\文件夹复制到content \ temp.

有关更多信息,请参阅 http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package

I want to create a NUGET package that adds several files to a certain solution folder. Specifically, the package must, on installation, do the following:

  1. Create a temp folder in the target project.
  2. Copy all the files matching an extension (say *.txt) to the temp folder.
  3. Move the files to Solution root.
  4. Create a Solution folder named "Solution Items".
  5. Add all the files just moved to that solution folder.
  6. Remove the temp folder from both solution and disk.

I use the package.nuspec file to create a temp directory and dump the files and init.ps1 to do the rest.

Unfortunately nothing happens beyond step 1.


This is my package.nuspec file.

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>IncludeFiles</id>
    <version>1.0</version>
    <authors>Chameera</authors>
    <owners>Chameera</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>dummy include files</description>
    <tags>dummy</tags>
  </metadata>
  <files>
    <file src="source\*.txt" target="content\temp" />
  </files>
</package>


This is my init.ps1 file.

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

$projectFullName = $project.FullName 
$fileInfo = new-object -typename System.IO.FileInfo -ArgumentList $projectFullName
$projectDirectory = $fileInfo.DirectoryName

$tempDirectory = "temp"
$sourceDirectory = "$projectDirectory\$tempDirectory"
$destinationDirectory = (get-item $sourceDirectory).parent.FullName

if(test-path $sourceDirectory -pathtype container)
{
 robocopy $sourceDirectory $destinationDirectory /XO

 $tempDirectoryProjectItem = $project.ProjectItems.Item($tempDirectory)
 $tempDirectoryProjectItem.Remove()

 remove-item $sourceDirectory -recurse
}

解决方案

when you open the package that you've created using the nuspec in nuget package explorer, did you see any .txt files in the content\temp folder?

when nuget.exe pack is called, it will copy the .txt files from the source\ folder to content\temp while making the package itself.

for more information, please refer to http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package

这篇关于Nuget复制文件并将其添加到解决方案级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆