【问题标题】:Adding references on Visual Studio Code from VSTS从 VSTS 添加对 Visual Studio Code 的引用
【发布时间】:2018-11-13 01:24:44
【问题描述】:

我在 VSTS(Visual Studio 团队服务)的提要中存储了一个私有包。我想将它添加到我正在使用 Visual Studio Code 开发的 .NET Core 项目中。

检查 VSTS 文档,要从私有源添加包,必须使用 NuGet CLI,因为 .NET 不支持私有存储库(或者至少我认为是这样,因为 Microsoft 建议我们改用 NuGet CLI) .

使用 NuGet CLI,添加包的命令是 NuGet install。但它会下载所有包,包括 .nupck、DLL 文件、大型文件等......(即各种 XML 文件)。而且它不会向项目添加必要的引用。使用.NET CLI添加包,在.csproj文件(项目文件)中添加引用,照常工作。

是否有一个命令可以重现完全相同的行为,例如我们在 Visual Studio 上添加包或使用 .NET 添加包 CLI 的 Visual Code?​​p>

如果没有,我该怎么办?我应该提取 DLL 文件并在 .csproj 文件中手动引用它吗?如果有任何更新,我怎么知道(在 Visual Studio 中,NuGet UI 显示更新,但在 Visual Studio Code 中,手动添加引用后...)

【问题讨论】:

    标签: visual-studio-code nuget azure-devops packages dotnet-cli


    【解决方案1】:

    无法通过 Visual Studio Code 或 NuGet CLI 将 NuGet 包添加到项目中

    对于命令nuget install(与nuget restore 功能相同),它只从指定的提要下载NuGet 包,但不会对项目进行任何更改。也可以参考帖子How to install a NuGet package on the command line to a Visual Studio project

    将 NuGet 包添加到项目的解决方法如下:

    1. 在 Visual Studio 中添加包

      您可以在 Visual Studio 中打开您的项目,然后通过 Visual Studio 添加 NuGet 包。

    2. 手动更改项目文件

      如果您尚未安装 Visual Studio。您也可以手动更改相关文件。

      比如将私人提要添加到nuget.config文件中,然后将.csproj文件更改为:

      <ItemGroup>
        <PackageReference Include="xxx" Version="xxx" />
      </ItemGroup>
      
    3. 通过dotnet add package 命令添加包

      您也可以使用dotnet add package 命令将 NuGet 包添加到您的项目中:

      dotnet add [<PROJECT>] package <PACKAGE_NAME>  [-v|--version]
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-08
      • 2016-12-19
      • 2022-11-09
      相关资源
      最近更新 更多