NuGet 如何将属性应用于文件 [英] NuGet how to apply properties to files

查看:48
本文介绍了NuGet 如何将属性应用于文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建 NuGet 包.我在 content 文件夹中放置了两个文件,exe 和 config 文件,它们将在用户安装此软件包时添加.

I am creating NuGet Package. I have put two files in content folder, exe and config files that will be added when user installs this package.

另外,我想更改这两个文件的 VS 项目属性.

In addition I would like to change VS project properties for these two files.

在构建包时我需要做什么?

What do I need to do for that when building the package?

推荐答案

当您说应用属性更改"时,您是指文件系统属性,例如上次修改时间、隐藏标志等吗?

When you say "apply properties change" do you mean file system properties such last modified time, hidden flag, etc.?

如果是这样,则有一组 PowerShell 脚本正在运行(如果它们存在于您的包中),您可以使用它来执行此操作.它不会在您构建包时发生,但会在有人安装包时运行 - 从用户的角度来看,这应该具有相同的效果.您可能需要 Init.ps1Install.ps1.

If so there are a set of PowerShell scripts that are run (if they exist in your package) you can use to do this. It won't happen when you build the package, but it will run when somebody installs the package - which should have the same effect form the users point of view. You probably want either Init.ps1 or Install.ps1.

来自 在软件包安装期间自动运行 PowerShell 脚本NuGet 文档中的和删除:

一个包可以包含 PowerShell 脚本,这些脚本在该软件包已安装或删除.NuGet 自动运行脚本基于使用以下约定的文件名:

A package can include PowerShell scripts that automatically run when the package is installed or removed. NuGet automatically runs scripts based on their file names using the following conventions:

  • Init.ps1 在第一次在解决方案中安装包时运行.
    • 如果相同的包安装到其他解决方案中的项目,脚本在这些期间不运行装置.
    • 脚本也会在每次解决方案出现时运行打开.例如,如果安装包,请关闭 Visual Studio,然后启动 Visual Studio 并打开解决方案 Init.ps1脚本再次运行.
    • Init.ps1 runs the first time a package is installed in a solution.
      • If the same package is installed into additional projects in the solution, the script is not run during those installations.
      • The script also runs every time the solution is opened. For example, if you install a package, close Visual Studio, and then start Visual Studio and open the solution, the Init.ps1 script runs again.
      • 如果同一个包安装在一个解决方案的多个项目中,每次安装包时脚本都会运行.
      • 包必须在 content 或 lib 文件夹中有文件才能运行 Install.ps1.只是在工具文件夹中有一些东西不会启动它.
      • 如果您的包也有 init.ps1install.ps1init.ps1 之后运行.
      • If the same package is installed in multiple projects in a solution, the script runs each time the package is installed.
      • The package must have files in the content or lib folder for Install.ps1 to run. Just having something in the tools folder will not kick this off.
      • If your package also has an init.ps1, install.ps1 runs after init.ps1.
      • $installPath 是安装包的文件夹
      • $toolsPath 是路径安装包所在文件夹中的工具目录
      • $package 是对包对象的引用.
      • $project 是一个引用 EnvDTE 项目对象并代表项目包安装到.注意:这在 Init.ps1 中将为空.在该案例没有对特定项目的引用,因为它在解决方案级别运行.定义了这个对象的属性在 MSDN 文档中.
      • $installPath is the path to the folder where the package is installed
      • $toolsPath is the path to the tools directory in the folder where the package is installed
      • $package is a reference to the package object.
      • $project is a reference to the EnvDTE project object and represents the project the package is installed into. Note: This will be null in Init.ps1. In that case doesn't have a reference to a particular project because it runs at the solution level. The properties of this object are defined in the MSDN documentation.

      这篇关于NuGet 如何将属性应用于文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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