简体   繁体   English

Nuget 封装,带调试和发布

[英]Nuget packages with both debug and release

In our work we have one team that develops libraries and other teams that develop projects using those libraries.在我们的工作中,我们有一个开发库的团队和其他使用这些库开发项目的团队。

The libraries team has much more experience than the projects one.图书馆团队比项目团队拥有更多的经验。

We created this environment here:我们在这里创建了这个环境:

All the libraries are in nuget packages, in a nuget server, in azure devops.所有库都在 nuget 包中,在 nuget 服务器中,在 azure devops 中。 We have source link in Azure devops.我们在 Azure devops 中有源链接。

But when we deploy the libraries, we have to choose between debug or release, and we have the pros and cons of each.但是当我们部署这些库时,我们必须在调试或发布之间做出选择,而且我们各有利弊。

My ideal nuget package would have both debug and release, and would select the same as the project running it.我理想的 nuget package 将同时具有调试和发布功能,并且 select 与运行它的项目相同。

this way I would have better debugging for the projects team, and maximum performance on the releases.这样我就可以为项目团队进行更好的调试,并在发布时获得最大的性能。

I talked with https://twitter.com/rrelyea and he gave some ideas, but they seem to complicated for the other teams to implement, or complex do manage.我与https://twitter.com/rrelyea进行了交谈,他提出了一些想法,但对于其他团队来说实施起来似乎很复杂,或者管理起来很复杂。

Like 2 nuget servers, one for debug, and one for release, and configure those different ones on the machines and on the build server.像 2 台 nuget 服务器,一台用于调试,一台用于发布,并在机器和构建服务器上配置这些不同的服务器。

Or 2 nuget packages, with.debug and.release on the name of the package, and configure the project to load a diffent one on each mode.或者 2 个 nuget 包,在 package 的名称上带有 .debug 和 .release,并配置项目以在每种模式下加载不同的。

The real problem is that I need a guarantee that all the packages have the same id and version on both servers.真正的问题是我需要保证所有包在两台服务器上都具有相同的 id 和版本。

Isn't there a more automatic way to pack the packages?没有更自动化的打包方式吗?

Simple if it's debug use the debug, if it's the release use the release.很简单,如果是调试就使用调试,如果是发布就使用发布。

By the way, how much performance difference is between debug and release in this case?顺便问一下,在这种情况下,调试和发布之间的性能差异有多大?

Isn't there a more automatic way to pack the packages?没有更自动化的打包方式吗?

Actually , nuget package does not have a mechanism to let a project to reference the debug output files or release output files based on the configuration of the main project. Actually , nuget package does not have a mechanism to let a project to reference the debug output files or release output files based on the configuration of the main project.

And when you pack a project, it does not have a function to include the Debug or Release output files at the same time and then let the main project-------when using Debug , reference the Debug content of the nuget, when using Release , reference the Release content of the nuget.而且打包项目的时候,没有function要同时包含Debug或者Release output文件然后让主项目-------使用Debug的时候,参考Z055824408469C382BFE79的Debug内容。使用Release时,参考 nuget 的Release内容。

So far , nuget is not yet so flexible, and it can't do the functions you mentioned above.到目前为止,nuget 还没有那么灵活,它不能做你上面提到的功能。

===================== ======================

As a suggestion , you should create two nuget packages( Debug or Release ) of the project and then manually install the corresponding package as required.作为建议,您应该创建项目的两个 nuget 包( DebugRelease ),然后根据需要手动安装相应的 package。

You can create a net standard library project, and add these in xxx.csproj file:您可以创建一个网络标准库项目,并将这些添加到xxx.csproj文件中:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <RootNamespace>PackageName</RootNamespace>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
  </PropertyGroup>

  
  <PropertyGroup Condition="'$(Configuration)'=='Debug'">
    <PackageId>PackageName_Debug</PackageId>      //name the nuget package which contains Debug key name
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)'=='Release'">
    <PackageId>PackageName_Release</PackageId>    //name the nuget package which contains Debug key name
  </PropertyGroup> 

  
  <PropertyGroup>
    <Version>1.0.0</Version>
    <Authors>your_name</Authors>
    <Company>your_company</Company>
  </PropertyGroup>


  <ItemGroup Condition="'$(Configuration)'=='Debug'">
    <None Include="$(ProjectDir)$(OutputPath)$(AssemblyName).pdb" Pack="true" PackagePath="lib\$(TargetFramework)"></None>
    <Compile Update="Class1.cs" Pack="true" PackagePath="Resource">
    </Compile>

    ...// add any source files

  </ItemGroup>
  
</Project>

And you can switch the Configuration to Debug or Release to build your project to generate the nupkg file under output folder.您可以将配置切换到调试发布来构建您的项目以在output文件夹下生成 nupkg 文件。

Note :注意

1) To generate a debug nuget package, you should contains the pdb file and source files into the nuget package and then you can debug it in the main project. 1) To generate a debug nuget package, you should contains the pdb file and source files into the nuget package and then you can debug it in the main project. There is a similar issue which contains the detailed steps about it.一个类似的问题,其中包含有关它的详细步骤。

2) You can define the package_id directly in the new sdk format project. 2)可以在新建的sdk格式项目中直接定义package_id And you should add Debug or Release to distinguish between them.您应该添加DebugRelease来区分它们。

More info about packing new sdk format project, you can refer to this document .有关打包新 sdk 格式项目的更多信息,您可以参考此文档

============================== ===============================

In addition , if you still want the initial feature(contain Debug or Release in the same package), you could suggest a feature on ourUser Voice Forum and I hope the Team will consider you idea carefully and give a satisfactory reply.另外,如果您仍然想要最初的功能(在同一个包中包含 Debug 或 Release),您可以在我们的User Voice 论坛suggest a feature ,我希望团队会仔细考虑您的想法并给出满意的答复。

Maybe... just add.pdb files from debug folder to Lib using Nuget Explorer也许......只需使用 Nuget Explorer 将调试文件夹中的.pdb 文件添加到 Lib

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

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