c#条件编译/按需引用 按需打包

2023-04-06  本文已影响0人  吉凶以情迁
<ItemGroup>
    <PackageReference Include="Dapper" Version="2.0.123" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.5" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.1" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
    <PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.3" />
    <PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.2.3" />
    <PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.2.3" />
    <PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.8.*" />
    <PackageReference Include="System.ServiceModel.Federation" Version="4.8.*" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.8.*" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.8.*" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.8.*" />
    
    <!-- 如果 DefineConstants 中没有定义 NO_SIGNALR 则添加 Microsoft.AspNetCore.SignalR 包 -->
    <PackageReference Include="Microsoft.AspNetCore.SignalR" Condition="!$(DefineConstants.Contains('NO_SIGNALR'))" Version="1.1.0" />
</ItemGroup>

宏定义控制代码部分是否会编译进去
也可以在上面的东西里控制
另外一种技术 根据引用智能的删掉没用到的代码
https://www.cnblogs.com/rupeng/p/16036266.html

上一篇下一篇

猜你喜欢

热点阅读