I created a simple NuGet package that includes an Init.ps1 script in the Tools folder. The script starts as follows:
我创建了一个简单的NuGet包,其中包含Tools文件夹中的Init.ps1脚本。该脚本如下所示:
param($installPath, $toolsPath, $package, $project)
$postBuildEvent = $project.Properties.Item("PostBuildEvent").Value
When installing the package in a Visual Studio 2012 project I get an error on $project.Properties.Item, because $project.Properties is null: "You cannot call a method on a null-valued expression". I checked if $project.Properties is null and it is.
在Visual Studio 2012项目中安装软件包时,我在$ project.Properties.Item上收到错误,因为$ project.Properties为null:“您无法在空值表达式上调用方法”。我检查了$ project.Properties是否为null。
Question is, why it is null. I just try to alter the post build event (like described here). Does anyone have clues?
问题是,为什么它是null。我只是尝试改变post build事件(如此处所述)。有人有线索吗?
Edit: If the code is inside Install.ps1 it works. It seems that the project properties are not available when first installing a package.
编辑:如果代码在Install.ps1中,它可以工作。首次安装软件包时,似乎项目属性不可用。
1 个解决方案
#1
0
The parameter list for init.ps1 is:
init.ps1的参数列表是:
param($installPath, $toolsPath, $package)
init.ps1 does not have the $project parameter because it is executed at the solution level and is not dependent on project.
init.ps1没有$ project参数,因为它在解决方案级别执行,并且不依赖于项目。
See here for more information: http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package
有关更多信息,请参见此处:http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package
#1
0
The parameter list for init.ps1 is:
init.ps1的参数列表是:
param($installPath, $toolsPath, $package)
init.ps1 does not have the $project parameter because it is executed at the solution level and is not dependent on project.
init.ps1没有$ project参数,因为它在解决方案级别执行,并且不依赖于项目。
See here for more information: http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package
有关更多信息,请参见此处:http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package