How can I find executables installed by NuGet packages?

这一生的挚爱 提交于 2019-12-11 03:14:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!