简体   繁体   English

相同的解决方案在不同的机器上产生不同的 Nuget package output

[英]Same solution on different machines producing different Nuget package output

I need help.我需要帮助。

My project has recently moved from .NET Framework 4.8 to.NET 6. We have everything uplifted and compiling, including the migration from packages.config to PackageReference.我的项目最近已从 .NET Framework 4.8 迁移到 .NET 6。我们提升并编译了所有内容,包括从 packages.config 迁移到 PackageReference。

This project is somewhat unique in that it has:这个项目有点独特,因为它有:

  1. An outward-facing Git repository that can connect to the inte.net一个面向外的 Git 存储库,可以连接到 inte.net
  2. A private Git repository that is offline离线的私有 Git 仓库

This means we have two builds, one for each repository.这意味着我们有两个构建,一个用于每个存储库。 To accomplish this, we have to copy the code and Nuget packages from the outward-facing Git repo to the private Git repo.为此,我们必须将代码和 Nuget 包从面向外部的 Git 存储库复制到私有 Git 存储库。 Obviously, we only want to copy the Nuget packages that are required since some packages already exist on the systems that use the private Git repo (eg,.NET 6 packages, DevExpress packages, etc.).显然,我们只想复制所需的 Nuget 包,因为使用私有 Git 存储库的系统上已经存在一些包(例如,.NET 6 包、DevExpress 包等)。

Here's the issue.这就是问题所在。

When I build the solution from Visual Studio on my laptop, the global packages folder contains 204 packages.当我在笔记本电脑上从 Visual Studio 构建解决方案时,全局包文件夹包含204 个包。 When I guild the exact same solution from Visual Studio on our public build system, the global packages folder contains 125 packages.当我在我们的公共构建系统上使用 Visual Studio 中的完全相同的解决方案时,全局包文件夹包含125 个包。 The total number of packages should be the same regardless of outward-facing system, and for the life of me, I cannot figure out why this is happening or how to fix it.无论面向外的系统如何,包裹的总数应该是相同的,而且对于我的生活,我无法弄清楚为什么会发生这种情况或如何解决它。

We have a NuGet.config file located in the solution folder (content below).我们在解决方案文件夹中有一个 NuGet.config 文件(内容如下)。 I have built using Visual Studio with Diagnostic output enabled and verified that the exact same NuGet config files are referenced and have the same content between my laptop and the public build system.我使用启用了诊断 output 的 Visual Studio 进行构建,并验证了完全相同的 NuGet 配置文件被引用并且在我的笔记本电脑和公共构建系统之间具有相同的内容。 This would lead me to believe that there is software (perhaps Visual Studio components?) installed on the public build system that are referenced from their installation location, but my laptop is having to pull them from one of the package sources.这会让我相信在公共构建系统上安装了从其安装位置引用的软件(也许是 Visual Studio 组件?),但我的笔记本电脑不得不从 package 来源之一中提取它们。 I simply don't know what else it could be, but I don't see any differences in this regard.我根本不知道它还能是什么,但我看不出这方面有什么不同。

Can anyone suggest things to investigate?谁能建议要调查的事情?

Here's our local NuGet.config file content:这是我们本地的 NuGet.config 文件内容:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="globalPackagesFolder" value=".\packages" />
    <add key="dependencyVersion" value="Highest" />
  </config>
  <packageSources>
    <clear />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
  <packageRestore>
    <clear />
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <clear />
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageManagement>
    <clear />
    <add key="format" value="1" />
    <add key="disabled" value="False" />
  </packageManagement>
</configuration>

(I know this isn't an answer, but it's too long for a comment... hopefully it can develop as we learn more) (我知道这不是答案,但评论太长了......希望它能随着我们了解更多而发展)

A couple ideas of where to look for differences:关于在哪里寻找差异的几个想法:

  1. Find the project.assets.json files in the obj folder for each project and compare between the builds.在每个项目的 obj 文件夹中找到 project.assets.json 文件并在构建之间进行比较。 This will show any differences in the restore graph that NuGet is generating.这将显示 NuGet 生成的还原图中的任何差异。
  2. Generate a binary log (binlog) from each build using the /bl flag (eg do.net build -bl or mbuild /bl depending on your build).使用 /bl 标志从每个构建生成二进制日志 (binlog)(例如do.net build -blmbuild /bl ,具体取决于您的构建)。 Use https://msbuildlog.com/ for reading the binlogs.使用https://msbuildlog.com/读取二进制日志。 You can find the references in each project build, and compare those (more manual, but each set of references can be sorted and then copied and diffed in a text editor).您可以在每个项目构建中找到参考,并比较它们(更多手动,但可以对每组参考进行排序,然后在文本编辑器中复制和比较)。 This might help show if some references are coming from an install location.这可能有助于显示某些引用是否来自安装位置。 One place to start might be to search for $rar (this is a shortcut for $task ResolveAssemblyReferences ), and look at the different OutputItems, expanded and sorted.一个起点可能是搜索$rar (这是$task ResolveAssemblyReferences的快捷方式),然后查看不同的 OutputItems、展开和排序。
  3. Compare results of building on the command line vs. in Visual Studio.比较在命令行上与在 Visual Studio 中构建的结果。 This can help isolate if VS is doing something to interfere or change the build.如果 VS 正在做一些事情来干扰或更改构建,这可以帮助隔离。

The problem was that the .NET 6 SDK was not installed on our public build system.问题是 .NET 6 SDK 没有安装在我们的公共构建系统上。 Let me see if I can explain.让我看看我能不能解释一下。

Up until November 2022, we were only targeting the .NET Framework, so we never had a reason to install the .NET SDK when upgrading Visual Studio.直到 2022 年 11 月,我们只针对 .NET 框架,因此我们在升级 Visual Studio 时从来没有理由安装 .NET SDK。 In late November, some of the members of our team began uplifting our solution to .NET 6 using the Visual Studio version we already had installed (17.2.9, I believe). 11 月下旬,我们团队的一些成员开始使用我们已经安装的 Visual Studio 版本(我相信是 17.2.9)将我们的解决方案升级到 .NET 6。 Obviously, they had to have the .NET 6 SDK installed on their local systems in order to build locally.显然,他们必须在本地系统上安装 .NET 6 SDK 才能在本地构建。 It is unclear whether they updated their Visual Studio version locally or downloaded the .NET 6 SDK directly.目前尚不清楚他们是在本地更新了 Visual Studio 版本还是直接下载了 .NET 6 SDK。

In any case, after the holidays, I began working to update our build system.无论如何,假期过后,我开始着手更新我们的构建系统。 One of the first things I did was update Visual Studio to v17.4.4 on my laptop, our public build system, and our various offline systems.我做的第一件事就是在我的笔记本电脑、我们的公共构建系统和我们的各种离线系统上将 Visual Studio 更新到 v17.4.4。 I made sure to check the .NET SDK option on the Individual Components page.我确保检查了单个组件页面上的 .NET SDK 选项。 I assumed this installed the .NET 6 SDK on these systems.我假设这在这些系统上安装了 .NET 6 SDK。

I was wrong.我错了。

Visual Studio 17.4.4 delivers the .NET 7 SDK, but we are specifically targeting .NET 6 because it is the long-term support version. Visual Studio 17.4.4 提供了 .NET 7 SDK,但我们特别针对 .NET 6,因为它是长期支持版本。

At some point in my efforts, I had apparently downloaded and installed the .NET 6 SDK on my laptop, but failed to make the connection that this needed to be done across the other systems as well.在我努力的某个时刻,我显然已经在我的笔记本电脑上下载并安装了 .NET 6 SDK,但未能建立连接,这也需要在其他系统上完成。

Thus, building on my laptop pulled the .NET 6 packages correctly (204).因此,在我的笔记本电脑上构建正确地提取了 .NET 6 个包 (204)。 On the public build system (which did not have the .NET 6 SDK), building resulted in a cadre of packages being pulled from the inte.net and the local .NET 7 SDK (125).在公共构建系统(没有.NET 6 SDK)上,构建导致从 inte.net 和本地 .NET 7 SDK (125) 中提取了一批软件包。

Once I installed the .NET 6 SDK on the public build system, it pulled the 204 packages that I was expecting.在公共构建系统上安装 .NET 6 SDK 后,它提取了我期望的 204 个包。

A huge shoutout to Jimmy for his suggestions.非常感谢吉米的建议。 I hope that between his answer and this one, others might find benefit.我希望在他的回答和这个回答之间,其他人可能会从中受益。

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

相关问题 在同一解决方案中的两个不同项目上使用相同的 Nuget package - Same Nuget package on two different projects in same solution 如何为在同一 VS 解决方案中使用不同 package 源的项目修复 Nuget 恢复 - How to fix Nuget restore for projects using different package sources within same VS solution 添加对同一Nuget包的引用,但针对不同的目标 - Add reference to same Nuget package but for different targets 是否可以在Visual Studio解决方案中引用不同的NuGet包版本? - Is it possible to reference different NuGet package versions in a Visual Studio solution? 是否可以将同一 Nuget 包的不同版本安装到代码的不同分支中? - Is it possible to install different versions of the same Nuget package into different branches of the code? 在同一个Project.Net Core中执行不同的Nuget Package版本 - Enforce Different Nuget Package Version in the same Project .Net Core 具有相同nuget包的项目引用了不同版本的程序集 - Projects with same nuget package referencing different version of assembly 我们可以在NuGet中添加2个不同版本的相同包 - Can we add 2 different versions of same package in NuGet 在不同的文件夹中恢复 nuget package - Restore nuget package in different folder Nuget并将软件包添加到解决方案 - Nuget and adding package to solution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM