热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在调试中使用项目引用,在发布中使用Nuget-UseProjectReferenceinDebugandNugetinRelease

Iwouldliketoworkinmyproject(A)andadependentNugetpackage(B)atthesametime,withoutt

I would like to work in my project (A) and a dependent Nuget package (B) at the same time, without the need to release the nuget package on each change.

我想同时在我的项目(A)和一个独立的Nuget包(B)中工作,而不需要在每次更改时发布Nuget包。

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包时?

2 个解决方案

#1


3  

One way is to manually edit the csproj file. If you have currently referenced the NuGet package, you will have a part in the csproj file like this:

一种方法是手动编辑csproj文件。如果您当前引用了NuGet包,那么您将在csproj文件中拥有如下部分:

....

  
    ..\packages\log4net.2.0.8\lib\net45-full\log4net.dll
    True
  
  
  
  
  
  
  
  

....

In this example, log4net is used. For your NuGet package, the public key token, version and so on is different. You can no change it to:

在本例中,使用log4net。对于NuGet包,公钥标记、版本等等是不同的。您不能将其更改为:

  
    
      Debug\log4net.dll
      True
    
  
  
    
      ..\packages\log4net.2.0.8\lib\net45-full\log4net.dll
      True
    
  

The Condition attribute in the ItemGroup element is doing the job between debug and release.

ItemGroup元素中的Condition属性在调试和发布之间执行。

#2


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”):

enter image description here

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只能在“发布”或“调试”模型中找到这两个名称空间:

enter image description here

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.

要解决这个错误,我们必须注释另一个配置模型中的命名空间,当您将配置模型从调试更改为发布时。

enter image description here


推荐阅读
author-avatar
hello簞調_290
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有