带有构建配置的 Nuget [英] Nuget with Build configurations

查看:34
本文介绍了带有构建配置的 Nuget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个项目转移到一个 nuget 包中.该项目中有预处理器指令,用于检查开发人员所在的自定义构建配置.如果它们在构建配置 A 中,则它会提取 A 服务设置,如果它们在 B 中,则它会提取 B 的设置.问题是当我打包这个服务并且 nuget 包在具有相同构建配置的单独进程中使用时,它不尊重开发者构建配置选择,因为 nuget 已经使用它内置的任何设置进行编译.我们已在单个 nuget 包中将其设置为 3 个 dll.

I'm moving over a project to make it into a nuget package. The project has preprocessor directives in it to check which custom build configuration the developer is in. If they are in Build config A then it pulls A service settings, if they are in B, then it pulls B's settings. The problem is when I package this service up and the nuget package is being used in a separate process with the same build configuration it doesn't respect the devs build configuration choice because the nuget has been compiled with whatever setting it was built in. We have set it up into 3 dlls in a single nuget package.

有没有办法在不修改 csproj 代码的情况下根据自定义构建配置选择它使用的 nuget dll?

Is there a way to choose which nuget dll it uses based on the custom build configuration without modifying the csproj code?

推荐答案

有没有办法在不修改 csproj 代码的情况下,根据自定义构建配置选择它使用的 nuget dll?

Is there a way to choose which nuget dll it uses based on the custom build configuration without modifying the csproj code?

据我所知,NuGet 不支持此功能.在单个项目的文件中只能有一个具有特定生成配置的 NuGet 包.而且,NuGet 现在只支持多个 .NET 框架版本,不支持多个配置.

This is not supported as far as I am aware with the NuGet. You can only have one NuGet package with a specific build configurations in a single project's file. Moreover, NuGet now only supports multiple .NET framework versions, not supported multiple configurations.

如果您有不同的构建配置,则可以有不同的 NuGet 包.此项目专供具有需要不同 NuGet 包的平台特定项目的库作者使用.

You can have different NuGet packages if you have different build configurations. This project is specific use by library authors who have platform specific projects that need different NuGet packages.

此外,不使用 NuGet 将程序集添加到您的项目可能更简单.直接用NuGet打包多个dll文件,然后直接使用条件引用您需要的程序集.

Besides, It may be simpler to not use NuGet to add the assemblies to your project. Just use NuGet to pack the package with multiple dlls file, then directly reference the assemblies you need with conditions.

这篇关于带有构建配置的 Nuget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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