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中发现它显示如下:

好像删除了所有“$ value”

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

最佳答案

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

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

09-27 04:49