简体   繁体   English

使用本地项目引用覆盖 nuget 包引用

[英]Override a nuget package reference with a local project reference

I'd like iterate on a nuget package without continuously pushing the package to a nuget feed.我想迭代一个 nuget 包,而不是不断地将包推送到 nuget 提要。

I'm wondering if it's possible to conditionally add a project reference instead of a nuget package reference via a target or props file in csproj files that would allow me to locally debug my nuget package.我想知道是否可以通过 csproj 文件中的目标或道具文件有条件地添加项目引用而不是 nuget 包引用,这将允许我在本地调试我的 nuget 包。

In my csproj I would have:在我的 csproj 中,我将拥有:

<Reference Include="A">
    if(Exists(localOverrides.props) {
        <HintPath>localOverrides.A.HintPath</HintPath>
    } else {
        <HintPath>..\packages\A.dll</HintPath>
    }
</Reference>

and localOverrides.props would be a file listed in my .gitignore that developers could add lines to like:并且 localOverrides.props 将是我的 .gitignore 中列出的文件,开发人员可以添加如下行:

A -> C:\Repos\A\bin\A.dll

Am I on the wrong path?我走错路了吗? Surely there must be a more sustainable way to quickly iterate and debug a nuget package then creating pre-release packages on every change当然,必须有一种更可持续的方式来快速迭代和调试 nuget 包,然后在每次更改时创建预发布包

The way I have always debugged Nuget package is once you have that package added to your solution through Nuget, you then make changes to the Nuget DLLs and just copy them into the correct folder in the packages folder for the project consuming the Nuget package.我一直调试 Nuget 包的方式是,一旦您通过 Nuget 将该包添加到您的解决方案中,然后您对 Nuget DLL 进行更改,并将它们复制到使用 Nuget 包的项目的包文件夹中的正确文件夹中。

All you have to do is compile the solution that Nuget project solution in debug mode and just copy/paste them into the consuming project's packages folder.您所要做的就是在调试模式下编译 Nuget 项目解决方案的解决方案,然后将它们复制/粘贴到使用项目的包文件夹中。 You could make this even simpler by writing a batch script and adding it as a post build event to the Nuget project that just copied the DLLs into the correct folder for you.您可以通过编写批处理脚本并将其作为构建后事件添加到刚刚将 DLL 复制到您的正确文件夹中的 Nuget 项目中来简化此操作。

If all you want to acomplish is to debug the NuGet package I suggest you use "dotpeek debug server" option.如果您只想调试 NuGet 包,我建议您使用“dotpeek 调试服务器”选项。 This way you don't need to do anything with the reference and simply debug the package or whatever you want.这样你就不需要对引用做任何事情,只需调试包或任何你想要的。 https://confluence.jetbrains.com/plugins/servlet/mobile#content/view/53336814 https://confluence.jetbrains.com/plugins/servlet/mobile#content/view/53336814

Sounds like you want a test project (unit or integration) in the same solution as your NuGet packaged assembly project.听起来您希望在与 NuGet 打包程序集项目相同的解决方案中拥有一个测试项目(单元或集成)。 Then you can prove it's correctness independently of any consumers of the NuGet package.然后,您可以独立于 NuGet 包的任何使用者证明它的正确性。 Good tests will also help ensure you don't break anything unintentionally when updating the package in the future.良好的测试还有助于确保您在将来更新软件包时不会无意中破坏任何东西。

There is a much easier way, in which you could use both: project references during development (faster), and package references during production.有一种更简单的方法,您可以同时使用这两种方法:开发期间的项目引用(更快)和生产期间的包引用。

In your .csproj project file:在您的.csproj项目文件中:

<ItemGroup Condition="'$(Configuration)'=='Debug'">
  <ProjectReference Include="../../../Library1/Library1.csproj" />
  <ProjectReference Include="../../../Library2/Library2.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'!='Debug'">
  <PackageReference Include="Library1" Version="1.0.0" />
  <PackageReference Include="Library2" Version="1.0.0" />
</ItemGroup>

In development : project compiled in debug mode, so the project reference will be used.在开发中:项目以调试模式编译,因此将使用项目引用。

In production (CI server, docker container): project compiled in release mode, so the package reference will be used.在生产中(CI 服务器,docker 容器):项目以发布模式编译,因此将使用包引用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM