NuGet 如何将属性应用于文件

发布于 2024-12-20 10:04:39 字数 137 浏览 1 评论 0原文

我正在创建 NuGet 包。我已将两个文件放在 content 文件夹中,即 exe 和配置文件,这些文件将在用户安装此软件包时添加。

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

构建包时我需要做什么?

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瑾兮 2024-12-27 10:04:39

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

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

来自在包安装和删除过程中自动运行 PowerShell 脚本< /a> 在 NuGet 文档中:

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

  • Init.ps1 首次在解决方案中安装软件包时运行。
    • 如果相同的软件包安装到其他
      解决方案中的项目,脚本在这些期间不会运行
      装置。
    • 每当解决方案出现时,该脚本也会运行
      打开。例如,如果安装包,请关闭 Visual Studio,
      然后启动 Visual Studio 并打开解决方案 Init.ps1
      脚本再次运行。
  • Install.ps1 在项目中安装软件包时运行。
    • 如果同一个包安装在解决方案的多个项目中,
      每次安装软件包时都会运行该脚本。
    • 软件包的 content 或 lib 文件夹中必须包含文件,Install.ps1 才能运行。仅在工具文件夹中包含某些内容并不能启动此操作。
    • 如果您的软件包还有 init.ps1,则 install.ps1init.ps1 之后运行。
  • Uninstall.ps1 每次卸载软件包时都会运行。
  • 这些文件应位于软件包的工具目录中。
  • 在文件顶部添加以下行:param($installPath, $toolsPath, $package, $project)
    • $installPath 是安装路径
      安装包的文件夹
    • $toolsPath 是路径
      安装包的文件夹中的tools目录
    • $package 是对包对象的引用。
    • $project
      对 EnvDTE 项目对象的引用并代表该项目
      包安装到.注意:在 Init.ps1 中这将为空。在
      该案例没有引用特定项目,因为它
      在解决方案级别运行。该对象的属性已定义
      在 MSDN 文档中。
  • 当您在创建脚本时在控制台中测试 $project 时,可以将其设置为 $project = Get-Project

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

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.

From Automatically Running PowerShell Scripts During Package Installation and Removal in the NuGet docs:

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 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.
  • Install.ps1 runs when a package is installed in a project.
    • 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.
  • Uninstall.ps1 runs every time a package is uninstalled.
  • These files should be located in the tools directory of your package.
  • At the top of your file, add this line: param($installPath, $toolsPath, $package, $project)
    • $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.
  • When you are testing $project in the console while creating your scripts, you can set it to $project = Get-Project
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文