的NuGet问题packages.config,项目引用和solutionwide包文件夹 [英] NuGet issues with packages.config, project references and the solutionwide packages folder

查看:1118
本文介绍了的NuGet问题packages.config,项目引用和solutionwide包文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们开始使用的NuGet和我们有一些问题:

We are starting to use NuGet and we are having some issues:

(只是为了确保我们理解了premises为的NuGet如何工作的)

  • 在packages.config(位于项目的根目录)创建,并为您添加,更新或删除程序包更新。在这个文件中的包的版本属性反映的完整版本正在使用,所以在这个意义上,它也是一个状态。它有可能将allowedVersions属性添加到包规范,然后将其限制在其上的版本可以被更新。为了让包还原工作,这个文件必须在源代码管理。

  • The packages.config (located in project-root) is created and updated as you add, update or delete packages. Within this file the package version property reflects the full version that is in use, so in this sense it is also a state. It is possible to add the allowedVersions property to the package specification, which is then a restriction on which versions that can be updated. To make package restore work, this file need to be under source control.

包文件夹位于解决方案根,并包含相关软件包的命名相匹配的包名(包括版本),允许多个版本的同一个包的子文件夹中下载的版本中使用通过在多项目溶液不同的项目。它是不宜源控制这些,因为它们是二进制文件和事实,即包恢复需要时可以重新创建。当一个软件包被更新的更新相匹配一个新的文件夹,包在里面创建。

The packages folder is located in the solution-root and contains a downloaded version of the dependent packages in a subfolder named to match the package names (including version), to allow multiple versions of the same package to be used by different projects in a multi-project solution. It is advised not to source control these as they are binaries and the fact that package restore can recreate them when needed. When a package is updated a new folder that matches the update is created with the package in it.

该项目文件包含对在包文件夹的包,为了构建工作,并为Visual Studio还能够提供自动完成,智能感知等。当一个软件包被更新的项目文件中引用更新以匹配包在包文件夹中的新位置。

The project-files contains a reference to the packages in the packages folder, in order for builds to work and for visual studio to also be able to provide autocomplete, intellisense and more. When a package is updated the references in the project-file are updated to match the new location of the package in the packages folder.

  1. 由于packages.config文件包条目包含了完整版本的信息,我们需要不断更新源控制回购的变化。或者,我们可以忽略的变化,大部分时间,但是当只在版本已经改变了我们将(在大多数情况下)可以忽略它们。 这似乎是很不必要的的NuGet恢复应该能够知道被允许(通过allowedVersions)的版本。

  1. Since the packages.config file package entries contains the full version-info we constantly need to update the source control repo with changes. Or, we could ignore the changes, most of the time, but when just the version has changed we would (in most cases) be able to ignore them. This seems very unnecessary as the NuGet restore should be able to know which versions are allowed (via allowedVersions).

在allowedVersions属性必须手动添加的东西,很容易遗忘。我们使用语义版本,所以对我们来说,安装即一个Foo-1.1.0版本,allowedVersions =[1,2),应暗示。

The allowedVersions property has to be manually added, something that is easily forgotten. We are using semantic versioning, so for us, when installing i.e. a Foo-1.1.0 version, allowedVersions="[1,2)" should be implied.

在加入allowedVersion随后的NuGet包还原似乎并没有能够找到 - $ P $租赁前的组件(?也许一个bug)

When adding the allowedVersion then NuGet package restore doesn't seem to be able to find -prerelease assemblies (maybe a bug?).

为什么包装上的解决方案级别由处理的NuGet?如果你工作在一个混合和匹配的解决方案,其中包含一个项目-A(回购-1)和项目B(回购-2),然后将溶液级封装是不会工作。也就是说,如果您保存解决方案文件在一个单独的位置,事情可能仍然工作AFAIK。但是,如果你再建立另一种解决方案,其中包含的项目-A(回购-1)和项目-C(回购-3),那么项目-A会突然需要一个包还原再次,更糟的是,该项目引用会改变以匹配的最后一次更改。让我们回到第一个解决方案,届时将有不工作的参考。检查这些必将使他们不为别人打工。

Why are packages handled by NuGet on a solution level? If you are working in a mix-and-match solution, which contains a project-A (repo-1) and project-B (repo-2), then the solution level packaging is not going to work well. That is, If you save that solution file in a separate location, things might still work afaik. But, if you then set up another solution which contains project-A (repo-1) and project-C (repo-3), then project-A would suddenly need a package-restore again, and worse, the project references would be changed to match the last change. Going back to the first solution will then have references that doesn't work. Checking in these will certainly make them not work for others.

在一个包更新,项目文件引用更新(以符合新foldernames与versionid在其中),并显示为未提交的更改。犯这种变化似乎是常态,但在我们看来,这不应该是必要的。

On a package update, the project-file references are updated (to match the new foldernames with versionid in them) and will appear as an uncommitted change. Committing this change seems to be the norm, but in our opinion this should not be necessary.

备注有关ExcludeVersion (可能被建议为解决上述问题:

Notes about ExcludeVersion (which could be suggested as a solution to the above problem:

  • 您只能提供当你手动执行的NuGet命令,AFAIK该选项。安装时/ Visual Studio中,不能使用经过的NuGet菜单更新软件包的选择。使用任何自动化工具意味着文件夹名和项目引用必须手动后固定。

  • You can only provide that option when you manually perform NuGet commands, afaik. When installing/updating packages via the NuGet menus in Visual Studio that option cannot be used. Using any of the automated tools means that the foldername and project-reference has to be fixed manually afterwards.

我们知道,ExcludeVersion不是默认设置,可能是由于支持,其中有人是工作在一个多项目的解决方案,在不同的项目依赖于不同版本的同一个包的情况。

We know that ExcludeVersion is not the default setting, probably due to supporting the cases where someone is working in a multi-project solution, where the different projects depend on different versions of the same package.

(不过,这可能需要在生态系统中的NuGet实质性的变化?)

A - packages.config

我希望在packages.config每个程序包元素可以抛弃allowedVersions,而是改版本是范围说明。软件包元件还应提供一种方式来分别确定从获取更新哪个源。最后,如​​果已安装的软件包如下语义版本那么版本属性会自动设置根据安装版本的版本范围。

I wish that each package element in packages.config could ditch allowedVersions and instead change version to be the range specifier. The packages element should also provide a way to separately identify which source to get the updates from. Finally, if an installed package follows Semantic Versioning then the version property should automatically setup the version-range according to the installed version.

样品packages.config:

Sample packages.config:

`<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Foo" version="[1,2] source="Development Feed">
</packages>`

这将:

  • 解决这个问题的package.config文件过多提交,因为版本属性不再是不断更新的。

  • Fix the issue with excessive commits of the package.config file, since the version property is no longer constantly updated.

没有必要记住设置语义版本控制项目范围。

No need to remember to set the range for semantically versioned projects.

确认包是从所需原料获取和那个时候不被寻找它在错误的来源浪费了。

Ensure that packages are fetched from the desired feed and that time is not wasted by looking for it in the wrong sources.

B - 包文件夹和安装的软件包中的名字

我希望包文件夹位于每个项目的根和子文件夹名称仅限于包名,不包括版本。 这将:

I wish that the packages folder was located in each project-root and that the subfolder names was limited to the package-name only, excluding the version. This would:

  • 解决这个问题的项目文件过多提交,因为在项目文件的项目引用现在更新后指向同一个包文件夹。

  • Fix the issue with excessive commits of the project-files, since the project-references in the project-file now points to the same package-folder after an update.

允许项目使用不同版本的同一个包,因为他们是那么真正相互独立的。

Allows projects to use different versions of the same package as they are then truly independent of each other.

我们将非常乐意听到的解决方案中列出的问题。

推荐答案

至于建议中的<一个href="http://stackoverflow.com/questions/21370676/nuget-enterprise-best-practices-for-different-maturity-levels-of-packages/">NuGet企业 - 对包不同成熟度的最佳实践,我认为你正在做的比需要更复杂的:)

As suggested in NuGet Enterprise - best practices for different maturity levels of packages, I think you are making things more complicated than necessary :)

  1. 为什么你会不会想要捕获的软件包的版本与该code编译?这对于可靠的诊断和可重复的构建的关键信息。鉴于你很可能犯code变回版本控制,提交有关详情包被用来帮助建立该源是非常有用的。
  2. 在安装即一个Foo-1.1.0版本,allowedVersions =当[1,2)应意味着的我不认为allowedVersions都不能真正地暗示,因为不是所有的的NuGet包坚持SemVer(看到的 log4net的1.2.11 )。建立一个的grep 的allowedVersions作为任CI生成或pre-提交/ pre-推部分开发的检查应该抓住这个。它不应该经常改变,并保持它的眼睛是很有用(如果其他球队和包使用SemVer正确,反正:))。
  3. 要找到你需要的 $ P $租赁前的$ P $租赁前的包 -Include $ P $租赁前的上的NuGet标志安装。
  4. 如果你工作在一个混合和匹配的解决方案,其中包含一个项目-A(回购-1)和项目B(回购2)的 - 你为什么安排您的code这样吗?在code为一个单一的解决方案应该住在同一回购所有。打破解决方案code跨越式回购是肯定会是痛苦的!
  5. 您可以告诉的NuGet使用的版本少的文件夹名称安装包( -ExcludeVersion )。
  1. Why would you not want to capture the version of the package with which the code was compiled? This is crucial information for reliable diagnostics and repeatable builds. Given that you'd likely be committing code changes back to version control, committing details of which packages were used to help build that source is very useful.
  2. "when installing i.e. a Foo-1.1.0 version, allowedVersions="[1,2)" should be implied" I do not think that allowedVersions can ever really be implied, because not all NuGet packages adhere to SemVer (see the debacle with log4net 1.2.11). Setting up a grep for allowedVersions as part of either CI build or pre-commit/pre-push Dev checks should catch this. It should not change often, and it's useful to keep an eye on it (if other teams and packages are using SemVer correctly, anyhow :) ).
  3. To find Prerelease packages you'll need the Prerelease or -IncludePrerelease flags on nuget install.
  4. "If you are working in a mix-and-match solution, which contains a project-A (repo-1) and project-B (repo-2)" - why have you arranged your code like this? The code for a single solution should live all in the same repo. Breaking solution code across repos is definitely going to be painful!
  5. You can tell nuget to use version-less folder names for installing packages (-ExcludeVersion).

我会强烈建议您使用命令行 nuget.exe 开沟在Visual Studio的NuGet整合赞成,构建脚本来代替。这特别涉及到#5,但与的NuGet一般相互作用。只与第三方公共包从nuget.org饲料工作时,Visual Studio集成是不错,但不够灵活,我喜欢在处理国内的NuGet饲料和包。

I would strongly recommend ditching the Visual Studio NuGet integration in favour using the command-line nuget.exe and build scripts instead. This relates particularly to #5 but to interaction with NuGet in general. The Visual Studio integration is nice when working solely with 3rd-party public packages from the nuget.org feed, but is not flexible enough for my liking when dealing with internal NuGet feeds and packages.

这篇关于的NuGet问题packages.config,项目引用和solutionwide包文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆