问题
My project needs to be packaged as a zip file for deployment. I want to create this zip file in a post build step.
To achieve this I have installed a 7-Zip command line package via NuGet. This package provides an executable which I want to call in my post build step. I know that I could call it by providing the path to the installed package but this path contains the version number of the package so a direct reference will break when the package is updated.
Is there some MSBuild variable that I could use to get the path to my installed packages' tools path?
回答1:
I don't think there's a way to avoid the version number in the path for the package, but you can do something like what the SlowCheetah nuget package does to make it more portable between developer machines, etc.
<PropertyGroup Label="SlowCheetah">
<SlowCheetahToolsPath>$([System.IO.Path]::GetFullPath( $(MSBuildProjectDirectory)\..\packages\SlowCheetah.2.5.12\tools\))</SlowCheetahToolsPath>
<SlowCheetah_EnableImportFromNuGet Condition=" '$(SlowCheetah_EnableImportFromNuGet)'=='' ">true</SlowCheetah_EnableImportFromNuGet>
<SlowCheetah_NuGetImportPath Condition=" '$(SlowCheetah_NuGetImportPath)'=='' ">$([System.IO.Path]::GetFullPath( $(MSBuildProjectDirectory)\Properties\SlowCheetah\SlowCheetah.Transforms.targets ))</SlowCheetah_NuGetImportPath>
<SlowCheetahTargets Condition=" '$(SlowCheetah_EnableImportFromNuGet)'=='true' and Exists('$(SlowCheetah_NuGetImportPath)') ">$(SlowCheetah_NuGetImportPath)</SlowCheetahTargets>
</PropertyGroup>
来源:https://stackoverflow.com/questions/24868812/how-can-i-find-executables-installed-by-nuget-packages