简体   繁体   English

是否有可能使NuGet.exe与Visual Studio断开连接?

[英]Is it possible to get NuGet.exe running disconnected from Visual Studio?

I've been wrestling with NuGet for a few days now and I'm turning to StackOverflow in frustration - hopefully someone here can be kind enough to point me in the right direction. 我已经和NuGet搏斗了好几天了,我沮丧地转向StackOverflow--希望这里有人能够指出我正确的方向。

I've used NuGet several times for simple one-man pet projects, but this is the first time I've used it for something I really care about and want to have fully continuous builds, etc. I'm trying to create a simple NAnt build script to get the source for Git, ensure the external dependencies have been brought down, compile, and run tests - vanilla CI. 我已经多次使用NuGet进行简单的单人宠物项目,但这是我第一次将它用于我真正关心的事情,并希望拥有完全连续的构建等等。我正在尝试创建一个简单的NAnt构建脚本以获取Git的源代码,确保外部依赖关系已被关闭,编译和运行测试 - vanilla CI。

I originally went down the path of trying to get solution restore working, but it just didn't work or I didn't how it worked. 我最初试图让解决方案恢复正常工作,但它只是没有用,或者我没有工作的方式。 Visual Studio is not on the build server and will not be installed there - that is not an option. Visual Studio不在构建服务器上,也不会安装在那里 - 这不是一个选项。 As an aside, I couldn't get solution restore to work just with two developers (one trying to bring down the source fresh and build cleanly). 顺便说一句,我无法让解决方案恢复只与两个开发人员一起工作(一个尝试将源清理干净并且干净地构建)。 I'm assuming it's because "allow solution restore" must be turned on everywhere (and is not by default). 我假设它是因为“允许解决方案恢复”必须在任何地方打开(默认情况下不是)。 I punted on that approach before I got to the bottom of it - frankly, having my package manager so tightly coupled to the IDE makes me uncomfortable and was hoping I could do it another way. 在我深究这个方法之前,我对这种方法进行了抨击 - 坦率地说,让我的软件包管理器与IDE紧密耦合让我感到不舒服,希望我能以另一种方式做到这一点。 The package managers I'm used to using are simple command line tools - the CI build script invokes it on build, and developers do it on demand. 我习惯使用的包管理器是简单的命令行工具 - CI构建脚本在构建时调用它,开发人员按需执行它。 I've spent the last two hours trying to get this working with the last 30 minutes in the NuGet source code. 我花了最后两个小时尝试在NuGet源代码中使用最后30分钟。 I feel like I'm fighting the tool and need to reboot. 我觉得我正在与该工具作斗争,需要重新启动。

Does anyone have any examples of the best to use NuGet in a multi-developer + CI scenario? 有没有人在多开发人员+ CI场景中有任何最好的NuGet示例? This is what I want: 这就是我要的:

  1. Any and all developers can get the source and run the tests in 3 or less clicks (preferably 1). 任何和所有开发人员都可以获得源并以3次或更少的点击次数(最好是1次)运行测试。 If the binaries are not present locally, that will be JIT fetched. 如果本地不存在二进制文件,则将获取JIT。 If they are there, they will be updated if necessary, etc. This would ideally not even require NuGet to be installed (ie NuGet.exe would need to be in my repo). 如果它们在那里,它们将在必要时更新等。理想情况下甚至不需要安装NuGet(即NuGet.exe需要在我的仓库中)。
  2. Do #1 via a CI server like Jenkins, TeamCity, etc. (preferably using the same script) 通过像Jenkins,TeamCity等CI服务器执行#1(最好使用相同的脚本)
  3. If its not overly fighting the tool, I would like to have all this disconnected from Visual Studio with a single packages.config file and all binaries dumped into a single Lib folder in the root of the repo. 如果它没有过度使用该工具,我希望将所有这些与Visual Studio断开连接,并将一个packages.config文件和所有二进制文件转储到repo根目录中的单个Lib文件夹中。

Any pointers would be very much appreciated. 任何指针都将非常感激。

TeamCity has a build step for that, called " NuGet Installer ", it fetch required packages from .sln file and download the locally. TeamCity有一个构建步骤,称为“ NuGet Installer ”,它从.sln文件中获取所需的包并在本地下载。 It does not require Visual Studio to run. 它不需要Visual Studio运行。

Read more about it here: http://confluence.jetbrains.com/display/TCD7/NuGet+Installer 在这里阅读更多相关信息: http//confluence.jetbrains.com/display/TCD7/NuGet+Installer

Below, how I think you can achieve each your requisites: 下面,我认为你可以达到每个要求:

  1. You need to "Enable NuGet Package Restore" in your solution: http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages 您需要在解决方案中“启用NuGet包还原”: http//docs.nuget.org/docs/workflows/using-nuget-without-committing-packages
  2. As @alexander-doroshenko mentioned for TeamCity you can use Nuget Installer: http://confluence.jetbrains.com/display/TCD7/NuGet+Installer , but if you want a script to run in Jenkins, try this (works at TC too, as a command line step) for each project: 正如@ alexander-doroshenko为TeamCity所提到的,您可以使用Nuget Installer: http ://confluence.jetbrains.com/display/TCD7/NuGet+Installer,但是如果您想在Jenkins中运行脚本,请尝试这个(在TC也可以使用) ,作为每个项目的命令行步骤:

    nuget.exe install "[Project folder]/packages.config" -source "" -solutionDir "" -OutputDirectory "packages" nuget.exe安装“[Project folder] /packages.config”-source“” - solutionDir“” - OutputDirectory“packages”

  3. This requisite will be done by item 1 and 2. 这一必要条件将由第1项和第2项完成。

There are several different solutions for integrating NuGet into your build process depending on how much integration you require. 根据您需要的集成程度,有几种不同的解决方案可以将NuGet集成到您的构建过程中。 In our case we wanted to use NuGet as package manager and allow developers to build their solutions even if they haven't got NuGet installed on their machine. 在我们的例子中,我们希望使用NuGet作为包管理器,并允许开发人员构建他们的解决方案,即使他们没有在他们的机器上安装NuGet。 For that to work we enabled package restore which adds the NuGet binaries to your solution folder and updates the project files. 为此,我们启用了包恢复,它将NuGet二进制文件添加到您的解决方案文件夹并更新项目文件。 Note that NuGet doesn't always do the update of the project files correctly. 请注意,NuGet并不总是正确地更新项目文件。 In our case we found that some project files got updated but others didn't. 在我们的例子中,我们发现一些项目文件已更新,但其他项目文件没有。 To verify that the project was updated you will need to open the project file as XML file. 要验证项目是否已更新,您需要将项目文件作为XML文件打开。 To achieve this load the solution and right click the project in question and select unload project. 要实现此加载解决方案并右键单击相关项目并选择卸载项目。 Then right click the project again and select edit [PROJECT_NAME]. 然后再次右键单击该项目,然后选择编辑[PROJECT_NAME]。 In the project file you should see 在项目文件中,您应该看到

  • A RestorePackages property in the first propertygroup. 第一个属性组中的RestorePackages属性。 This property should have the value true 此属性的值应为true
  • An import statement at the very end of the project file. 项目文件末尾的import语句。 This import statement should point to the 'NuGet.targets file that accompanies the NuGet binary. 此import语句应指向NuGet二进制文件附带的'NuGet.targets文件。

Below is an example of one of our project files (heavily edited) 以下是我们的一个项目文件的示例(经过大量编辑)

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <SolutionDir Condition="'$(SolutionDir)' == '' or '$(SolutionDir)' == '*undefined*'">$(MSBuildProjectDirectory)\..</SolutionDir>
    <ProjectGuid>{8B467882-7574-41B2-B3A8-2F34DA84BE82}</ProjectGuid>
    <OutputType>Library</OutputType>
    <RootNamespace>MyCompany.MyNamespace</RootNamespace>
    <AssemblyName>MyCompany.MyNamespace</AssemblyName>

    <!-- Allow NuGet to restore the packages if they are missing -->
    <RestorePackages>true</RestorePackages>
  </PropertyGroup>
  <Import Project="$(SolutionDir)\BaseConfiguration.targets" />
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="MyClass.cs" />
    <!--
        .... MANY MORE FILES HERE
    -->
  </ItemGroup>

  <!-- Import the Nuget.targets file which integrates NuGet in the build process -->
  <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

The next step you'll need to take is to provide a solution level NuGet configuration file in which you'll indicate where the packages need to be 'installed' and what the URL of the package repository is. 您需要采取的下一步是提供一个解决方案级别的NuGet配置文件,您可以在其中指明需要“安装” 软件包的位置以及软件包存储库的URL。 In our case the solution directory structure looks like: 在我们的例子中,解决方案目录结构如下:

(D) root
    (D) build
    (D) packages
    (D) source
        (D) .nuget
            NuGet.config
            NuGet.exe
            NuGet.targets
        (D) MyCoolProject
            MyCoolProject.csproj
        MyCoolProject.sln
    (D) templates
    NuGet.Config

Where (D) indicates a directory. 其中(D)表示目录。

The NuGet.config file contains the following configuration settings. NuGet.config文件包含以下配置设置。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageRestore>
    <add key="enabled" value="True" />
  </packageRestore>
  <config>
    <add key="repositorypath" value="packages" />
  </config>
  <packageSources>
    <add key="OurPackageServer" value="PACKAGE_SERVER_ADDRESS" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
</configuration>

This configuration file indicates that package restore is enabled, that the repository path (where the packages are placed) is the packages directory and which package sources are active. 此配置文件指示已启用程序包还原,存储库路径(放置程序包的位置)是程序包目录以及哪些程序包源处于活动状态。

By placing a NuGet.config file in the root directory we can use the hierarchical configuration option with NuGet. 通过在根目录中放置NuGet.config文件,我们可以使用NuGet的分层配置选项。 This allows the individual solutions to override computer specific configurations. 这允许各个解决方案覆盖计算机特定的配置。 The other benefit is that this way we don't need to have NuGet installed on the build server (because the executable and the configurations are in the repository). 另一个好处是,这样我们就不需要在构建服务器上安装NuGet(因为可执行文件和配置在存储库中)。

With this setup developers can build the solution from Visual Studio. 通过此设置,开发人员可以从Visual Studio构建解决方案。 The build should work fine on developers machines even if they don't have NuGet installed. 即使没有安装NuGet,构建也应该在开发人员机器上正常工作。 Note however that they won't be able to add packages to a project without having NuGet installed in visual studio. 但请注意,如果没有在Visual Studio中安装NuGet,他们将无法将包添加到项目中。 On the build server you can simply use MsBuild to build the solution which will automatically download the packages from your package repository. 在构建服务器上,您只需使用MsBuild构建解决方案,该解决方案将自动从软件包存储库下载软件包。 Visual Studio is not required to be installed on the build machine for that (just the .NET framework of your choice). Visual Studio不需要在构建机器上安装(只是您选择的.NET框架)。

暂无
暂无

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

相关问题 Nuget.exe安装 - Microsoft.CSharp已经具有System.Dynamic.Runtime的依赖项 - Nuget.exe Install — Microsoft.CSharp already has a dependency for System.Dynamic.Runtime 如何配置NuGet.exe命令工具行查找包的位置 - How to configure where NuGet.exe Command Tool line looks for packages 持续集成-从TeamCity部署NuGet到Visual Studio Online Feed - Continuous Integration - Deploying NuGet to Visual Studio Online Feed from TeamCity 如何从jenkins构建Visual Studio安装程序项目(.vdproj)以生成.exe和.msi文件? - How to build visual studio installer project (.vdproj) from jenkins to generate .exe and .msi files? Visual Studio Team Services持续集成:NuGet Restore任务失败 - Visual Studio Team Services Continuous Integration: NuGet Restore Task Failed 是否可以在 Windows 容器中安装 Visual Studio - Is it possible to install Visual Studio in a Windows Container 使用Web部署程序包或NuGet程序包作为Visual Studio Team Services中的构建工件 - Use a Web Deployment Package or NuGet package as build artifact in Visual Studio Team Services MSTest-使用Visual Studio服务(TFS和持续集成)运行测试 - MSTest - Running tests using visual studio services (TFS and Continous Integration ) 在未安装Visual Studio的TeamCity构建服务器上运行MSTests - Running MSTests on TeamCity build server without Visual Studio installed 使用 Visual Studio 构建工具构建和运行单元测试 - Building and running unit tests with Visual Studio build tools
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM