NuGet - install.ps1 没有被调用

发布于 2024-11-27 08:29:59 字数 448 浏览 0 评论 0原文

我正在尝试创建我的第一个 NuGet 包。我不知道为什么我的 install.ps1 脚本没有被调用。这是

--Package
|
 - MyPackage.nuspec
 - tools
 |
  - Install.ps1
  - some_xml_file

我使用此命令行构建包的 目录结构 nuget.exe pack MyPackage.nuspec

当我从 VS 包管理器控制台安装包时 install.ps1 不会被调用。

我想也许我在脚本中遇到了一些错误,这就是原因,所以我注释掉了所有内容,但

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

我没有看到 ECHO 出现在包管理器控制台中。有什么问题吗?

I'm trying to create my first NuGet package. I don't know why my install.ps1 script does not get called. This is directory structure

--Package
|
 - MyPackage.nuspec
 - tools
 |
  - Install.ps1
  - some_xml_file

I build package using this command line
nuget.exe pack MyPackage.nuspec

When I Install-Package from VS Package Manager Console install.ps1 does not get called.

I thought that maybe I had some errors in script and that's the reason so I commented out everything but

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

But I don't see ECHO appearing in Package Manager Console. What can be wrong?

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

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

发布评论

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

评论(3

终止放荡 2024-12-04 08:29:59

仅当 \lib 和/或 \content 文件夹中有内容时才会调用 Install.ps,而不是“仅工具”不过,包裹。请参阅此处

软件包的 content 或 lib 文件夹中必须有文件才能运行 Install.ps1。仅在工具文件夹中包含某些内容并不能启动此操作。

请改用 Init.ps1 (但是,每次打开解决方案时都会执行此操作)。

Install.ps will only be invoked if there is something in the \lib and/or \content folder, not for a "tools only" package, though. See here:

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.

Use the Init.ps1 instead (however, this will be executed every time the solution is opened).

回忆躺在深渊里 2024-12-04 08:29:59

在 v3 中不再调用 Install.ps1(和 Uninstall.ps1),但您可以使用 Init.ps1。请参阅此处

Powershell脚本支持已修改为不再执行安装
并卸载脚本,但初始化脚本仍然执行。一些
这样做的原因是无法确定哪个包
当并非所有包都被直接引用时需要运行脚本
通过一个项目。

Install.ps1 (and Uninstall.ps1) are no longer called in v3, but you can use Init.ps1. See here:

Powershell script support was modified to no longer execute install
and uninstall scripts, but init scripts are still executed. Some of
the reasoning for this is the inability to determine which package
scripts need to be run when not all packages are directly referenced
by a project.

半葬歌 2024-12-04 08:29:59

有时,安装脚本的替代方案可以是包目标文件。该目标文件会自动编织到项目文件(csproj,...)中,并通过构建进行调用。

要允许 Nuget 找到此目标文件并将其编入其中,必须执行以下两件事:

  • 目标文件的名称必须为 .targets
  • 它必须保存在文件夹中build 在包的顶层

如果您想将某些内容复制到输出文件夹(例如一些其他二进制文件,如本机 DLL),您可以将这些二进制文件放入文件夹 binaries< 下的包中/code> 并在中使用此片段用于复制的目标文件:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="CopyBinaries" BeforeTargets="BeforeBuild">
        <CreateItem Include="$(MSBuildThisFileDirectory)..\binaries\**\*.*">
            <Output TaskParameter="Include" ItemName="PackageBinaries" /> 
        </CreateItem>

        <Copy SourceFiles="@(PackageBinaries)"
              DestinationFolder="$(OutputPath)\%(RecursiveDir)"
              SkipUnchangedFiles="true"
              OverwriteReadOnlyFiles="true"
        />
    </Target>
</Project>

An alternative to the install script can sometimes be a package targets file. This targets file is automatically weaved into the project file (csproj, ...) and gets called with a build.

To allow Nuget to find this targets file and to weave it in, these two things are mandatory:

  • the name of the targets file must be <package-name>.targets
  • it must be saved in the folder build at the top level of the package

If you like to copy something to the output folder (e.g. some additional binaries, like native DLLs) you can put these binaries into the package under folder binaries and use this fragment in the targets file for the copying:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="CopyBinaries" BeforeTargets="BeforeBuild">
        <CreateItem Include="$(MSBuildThisFileDirectory)..\binaries\**\*.*">
            <Output TaskParameter="Include" ItemName="PackageBinaries" /> 
        </CreateItem>

        <Copy SourceFiles="@(PackageBinaries)"
              DestinationFolder="$(OutputPath)\%(RecursiveDir)"
              SkipUnchangedFiles="true"
              OverwriteReadOnlyFiles="true"
        />
    </Target>
</Project>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文