问题
Configure NuGet package to add a build event when installed
I follow Paul's answer and do it
$project.Properties.Item("PreBuildEvent").Value = "your build event here"
Below is my 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"
but i find that in my vs2013,it shows like:
seems like remove all the "$value"
Could u tell me how to solve this?
I want that content in my install.ps1 is same with content in pre build event in my vs
回答1:
Try using single quotes instead of double quotes.
In PowerShell if you use double quotes then any variables (e.g. $SolutionDir) inside the double quotes will be expanded and replaced with the variable values. In your case these variables do not exist so they are replaced in the string with empty strings.
来源:https://stackoverflow.com/questions/25840375/how-to-add-prebuildevent-in-install-ps1-in-nuget