4
Is it possible to do a project-reference the Nuget project (B) from the Solution (A) when building Debug. And when building Release use the Nuget package from Source?
在构建调试时,是否可以从解决方案(a)中引用Nuget项目(B)。当构建版本使用来自源代码的Nuget包时?
Certainly, but there are some restrictions you need to know.
当然,但是有一些限制你需要知道。
First, the ID of the NuGet package should different from the name of the reference project, otherwise, the reference from NuGet will replace the project reference.(For example, TestProjectReferenceForDebug
is the name of the project reference, if you want to use project reference and NuGet package at the same time, you could not use this project to create the NuGet package directly, so I created a same project with different name to create the NuGet package "TestNuGetForRelease
"):
首先,NuGet包的ID应该与引用项目的名称不同,否则,NuGet的引用将代替项目引用。(例如,TestProjectReferenceForDebug项目引用的名称,如果您想要使用的项目参考和NuGet包在同一时间,你不能直接使用这个项目创建NuGet包,所以我创建了一个相同的项目用不同的名称来创建NuGet包“TestNuGetForRelease”):
Second, you should use Condition
attribute in the ItemGroup
element, otherwise, there is an ambiguous reference between 'TestProjectReferenceForDebug
' and 'TestNuGetForRelease
', so we need add the Condition
attribute in the ItemGroup
element
其次,您应该在ItemGroup元素中使用条件属性,否则,在'TestProjectReferenceForDebug'和'TestNuGetForRelease'之间存在一个不明确的引用,因此我们需要在ItemGroup元素中添加条件属性
..\packages\TestNuGetForRelease.1.0.0\lib\net462\TestNuGetForRelease.dll
True
{90424b17-2231-4d7d-997b-608115d9f4d9}
TestProjectReferenceForDebug
Third, after we add the Condition
attribute in the ItemGroup
element with debug
and release
, we could use project reference in Debug
and Nuget in Release
, however, if we use those namespace in one .cs file at same time, we need to add those two namespace, then you will get an error "The referenced component 'xxx' could not be found". That because VS could not find those two namespace only in the "Release" or "Debug" model:
第三,后添加ItemGroup条件属性的元素与调试和发布,我们可以使用项目在调试和Nuget参考版本,然而,如果我们使用这些名称空间在一个cs文件在同一时间,我们需要添加这两个名称空间,那么您将得到一个错误“引用的组件“xxx”不能被发现”。因为VS只能在“发布”或“调试”模型中找到这两个名称空间:
To resolve this error, we have to annotate the namespace which in another configuration model when you change the configuration model from Debug to Release.
要解决这个错误,我们必须注释另一个配置模型中的命名空间,当您将配置模型从调试更改为发布时。