简体   繁体   English

在Powershell中使用nuget外部工具

[英]Use nuget external tool in powershell

Some nuget packages add external tools eg. 一些nuget软件包添加了外部工具,例如。 OpenCover installs its executables in $env:USERPROFILE\\.nuget\\packages\\opencover\\<version>\\tools . OpenCover将其可执行文件安装在$env:USERPROFILE\\.nuget\\packages\\opencover\\<version>\\tools These can be executed from the PackageManager console in Visual Studio. 这些可以从Visual Studio中的PackageManager控制台执行。 eg. 例如。

PM> OpenCover.Console.exe

But I'm having no luck getting the command running outside PackageManager (specifically, I'm trying to run OpenCover.Console.exe in a PowerShell build script). 但是我无法让命令在PackageManager外部运行(特别是,我试图在PowerShell构建脚本中运行OpenCover.Console.exe )。

According to https://docs.microsoft.com/en-us/nuget/tools/package-manager-console#setting-up-a-nuget-powershell-profile these tools are available to a Powershell nuget profile. 根据https://docs.microsoft.com/zh-cn/nuget/tools/package-manager-console#setting-up-a-nuget-powershell-profile的说明,这些工具可用于Powershell nuget概要文件。 But I can't seem to find a way to specify a profile file to use in a Powershell session ( Powershell doesn't take a profile file arg and sourcing the profile file in a session throws an error). 但是我似乎找不到一种方法来指定要在Powershell会话中使用的配置文件( Powershell不会获取配置文件arg,而在会话中获取配置文件会引发错误)。

Any suggestions how to run these nuget tools outside of PackageManager? 有什么建议如何在PackageManager外部运行这些nuget工具吗?

Not sure how OpenCover works, but nuget is not part of the normal msbuild toolchain; 不确定OpenCover的工作方式,但是nuget不是正常的msbuild工具链的一部分。 its executed separately. 其单独执行。 Most builds I've worked with, the nuget restore step is separate, executed before the msbuild step. 我使用过的大多数构建,nuget restore步骤是独立的,在msbuild步骤之前执行。

Also, nuget is not "installed" in your OS, nor should you rely on it being available on a machine - it's just a standalone tool. 另外,nuget不会“安装”在您的操作系统中,也不应该依赖于它在计算机上的可用性-它只是一个独立的工具。 You have to download, extract and add it to your path, or execute it directly - something like this (powershell): 您必须下载,提取并将其添加到路径中,或者直接执行它-类似于以下内容(powershell):

$args = @("restore", "D:\path\to\my\build.sln")
& "D:\path\to\nuget.exe" $args

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM