如何在Nuget中的install.ps1中添加PreBuildEvent

时间:2014-09-15 03:20:03

标签: visual-studio nuget pre-build-event

Configure NuGet package to add a build event when installed
我按照保罗的回答进行操作

$project.Properties.Item("PreBuildEvent").Value = "your build event here"

以下是我的install.ps1

$project.Properties.Item("PreBuildEvent").Value = "IF $(ConfigurationName) == Debug IF $(PlatformName) == ARM goto DebugARM
IF $(ConfigurationName) == Debug IF $(PlatformName) == x86 goto Debugx86
IF $(ConfigurationName) == Release IF $(PlatformName) == ARM goto ReleaseARM
IF $(ConfigurationName) == Release IF $(PlatformName) == x86 goto Releasex86

:DebugARM
echo build SDK-DebugARM
copy $(SolutionDir)packages\AMap.2.2.0\AMAP3DEngine\lib\arm\debug\LibMap.dll $(ProjectDir)LibMap.dll /Y
copy $(SolutionDir)packages\AMap.2.2.0\AMAP3DEngine\references\arm\debug\AMapSDKV2Comp.dll $(SolutionDir)packages\AMap.2.2.0\lib\AMapSDKV2Comp.dll /Y
copy $(SolutionDir)packages\AMap.2.2.0\AMAP3DEngine\references\arm\debug\AMapSDKV2Comp.winmd $(SolutionDir)packages\AMap.2.2.0\lib\AMapSDKV2Comp.winmd /Y
exit 0

:Debugx86
echo build SDK-Debugx86
copy $(SolutionDir)packages\AMap.2.2.0\AMAP3DEngine\lib\x86\debug\LibMap.dll $(ProjectDir)LibMap.dll /Y
copy $(SolutionDir)packages\AMap.2.2.0\AMAP3DEngine\references\x86\debug\AMapSDKV2Comp.dll $(SolutionDir)packages\AMap.2.2.0\lib\AMapSDKV2Comp.dll /Y
copy $(SolutionDir)packages\AMap.2.2.0\AMAP3DEngine\references\x86\debug\AMapSDKV2Comp.winmd $(SolutionDir)packages\AMap.2.2.0\lib\AMapSDKV2Comp.winmd /Y
exit 0

:ReleaseARM
echo build SDK-ReleaseARM
copy $(SolutionDir)packages\AMap.2.2.0\AMAP3DEngine\lib\arm\release\LibMap.dll $(ProjectDir)LibMap.dll /Y
copy $(SolutionDir)packages\AMap.2.2.0\AMAP3DEngine\references\arm\release\AMapSDKV2Comp.dll $(SolutionDir)packages\AMap.2.2.0\lib\AMapSDKV2Comp.dll /Y
copy $(SolutionDir)packages\AMap.2.2.0\AMAP3DEngine\references\arm\release\AMapSDKV2Comp.winmd $(SolutionDir)packages\AMap.2.2.0\lib\AMapSDKV2Comp.winmd /Y
exit 0

:Releasex86
echo build SDK-Releasex86
copy $(SolutionDir)packages\AMap.2.2.0\AMAP3DEngine\lib\x86\release\LibMap.dll $(ProjectDir)LibMap.dll /Y
copy $(SolutionDir)packages\AMap.2.2.0\AMAP3DEngine\references\x86\release\AMapSDKV2Comp.dll $(SolutionDir)packages\AMap.2.2.0\lib\AMapSDKV2Comp.dll /Y
copy $(SolutionDir)packages\AMap.2.2.0\AMAP3DEngine\references\x86\release\AMapSDKV2Comp.winmd $(SolutionDir)packages\AMap.2.2.0\lib\AMapSDKV2Comp.winmd /Y
exit 0"

我发现在我的vs2013中,它显示如下: enter image description here

似乎删除所有" $ value"

你能告诉我怎么解决这个问题吗? 我希望我的install.ps1中的内容与我的vs中的预构建事件中的内容相同

1 个答案:

答案 0 :(得分:2)

尝试使用单引号而不是双引号。

在PowerShell中,如果使用double quotes,则双引号内的任何变量(例如$ SolutionDir)将被展开并替换为变量值。在您的情况下,这些变量不存在,因此它们将在字符串中替换为空字符串。