NuGet 缓存和版本控制问题 [英] NuGet Cache And Versioning Issues

查看:12
本文介绍了NuGet 缓存和版本控制问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 NuGet 预发布包时遇到问题,想知道其他人在这种情况下做了什么.NuGet 功能似乎与 Maven 中的预期行为完全不同,坦率地说,很奇怪.举个简单的例子,假设我们有程序集 FooAssembly 和 BarAssembly,其类定义如下:

I'm having issues with NuGet prerelease packages and was wondering what others had done in this situation. NuGet functionality seems completely different, and frankly, strange, from expected behavior in Maven. For a quick example, let's say we have assemblies FooAssembly and BarAssembly, with classes defined as follows:

富:

namespace Foo {
    class FooClass {
         public void TestA(){
         }
    }
}

酒吧:

namespace Bar {
    class BarClass {
         public static void Main(string[] args){
             FooClass foo = new FooClass();
             foo.TestA();
         }
    }
}

当我构建 Foo 时,它会生成 Foo-1.0.0-SNAPSHOT.nupkg.当我将它作为依赖项添加时,NuGet 会将其安装到 Bar 中,并将其放置在 %APPDATA% 下的本地缓存和源代码树中的包文件夹中.现在,如果我将方法 TestB() 添加到 Foo 并重建,它还会生成 Foo-1.0.0-SNAPSHOT.nupkg.我的构建按预期将这个新的 nupkg 文件放入我的 %APPDATA% 缓存中.但是,当我尝试重建 Bar 时,NuGet 没有检测到我在 %APPDATA% 中的 nupkg 已更改,因此没有可用的新 TestB 方法.我必须手动删除 src/packages 文件夹(或者至少是包中的 Foo 子目录)才能从我的缓存中重新获取包.

When I build Foo, it's versioned such that it generates Foo-1.0.0-SNAPSHOT.nupkg. NuGet installs this into Bar when I add it as a dependency, placing it in both my local cache under %APPDATA% and a packages folder in my source tree. Now, if I add method TestB() to Foo, and rebuild, it also generates Foo-1.0.0-SNAPSHOT.nupkg. My build places this new nupkg file into my %APPDATA% cache as expected. However, when I try to do a rebuild of Bar, NuGet doesn't detect that my nupkg in %APPDATA% has changed, and therefore doesn't have the new TestB method available. I have to manually delete the src/packages folder (or at least the Foo subdirectory in packages) for it to reacquire the package from my cache.

在 Maven 中,如果我要重建 Foo 并添加了 TestB 方法,它会将 Foo-1.0.0-SNAPSHOT 放在我的 .m2 缓存中,并且 Bar 将链接到新版本的 jar 并知道 TestB.

In Maven, if I were to rebuild Foo with the TestB method added, it would place Foo-1.0.0-SNAPSHOT in my .m2 cache, and Bar would link against the new version of the jar and would know about TestB.

我的问题是,首先,我是否缺少 NuGet 的某些内容?其次,如果我不是,人们做了什么来解决这个缺点?添加 MSBuild 预构建步骤以清除项目包缓存?将内部版本号附加到 SNAPSHOT 的末尾(例如 SNAPSHOT42 ......这对于项目中的多个开发人员来说似乎会有问题)?

My question is, firstly, am I missing something with NuGet? Secondly, if I'm not, what have people done to work around this shortcoming? Add an MSBuild pre-build step to wipe out the project package cache? Append build numbers to the end of SNAPSHOT (e.g. SNAPSHOT42...this seems like it would be problematic with more than one developer on the project)?

感谢任何见解.谢谢.

推荐答案

WARNING: Out of Date

截至 2018 年,此答案已过时 - 有关更新信息,请参阅我的其他答案.

NuGet 并不像 Maven 那样真正支持 SNAPSHOT 依赖项,尽管存在 未解决问题 实现类似的功能,并就此类功能进行讨论.

NuGet doesn't really support SNAPSHOT dependencies like Maven does, although there is an open issue to implement something similar and a discussion about such functionality.

建议的一种可能性是编写一个脚本:

A possibility suggested was to write a script to:

  • 生成具有不同版本的新 Foo 包
  • 更新 Bar 以引用最新版本的 Foo

另外,当我处理自己的项目时,我总是从源代码构建和引用 Foo.然后,一旦 Foo 项目变得足够稳定以至于我不再更新它,我就开始停止通过源代码引用 Foo 而是构建它并作为 nuget 包引用.

Alternatively when I work on my own projects, I always build and reference Foo from source. Then, once Foo project becomes stable enough that I don't update it much anymore, I then start stop referencing Foo via source and instead build it and reference as a nuget package.

这篇关于NuGet 缓存和版本控制问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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