net6 net8 发布失败的几个bug应急办法

定位了几个发布失败的错误,问了微软,感觉还是应急办法,目前还未修复,VS版本2022 17.8.3

 

  • net6 引用最新hosting后发布win-x64 win-x86错误

项目配置:

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

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
  </ItemGroup>

</Project>

 

发布配置:

<Project>
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>Any CPU</Platform>
    <PublishDir>bin\Release\net6.0-windows\publish\win-x64\</PublishDir>
    <PublishProtocol>FileSystem</PublishProtocol>
    <_TargetId>Folder</_TargetId>
    <TargetFramework>net6.0-windows</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <SelfContained>true</SelfContained>
    <PublishSingleFile>false</PublishSingleFile>
    <PublishReadyToRun>false</PublishReadyToRun>
  </PropertyGroup>
</Project>

 

发布报错后永远智能看到个webtools的报错,根本查不出原因来

微软回复:

https://developercommunity.visualstudio.com/t/net6-wpf-publish-failed-when-include-hos/10552458?page=31&pageSize=15&sort=active&openOnly=false&closedOnly=false&topics=test-plans

增加配置<LangVersion>12.0</LangVersion>

变成

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

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UseWPF>true</UseWPF>
    <LangVersion>12.0</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
  </ItemGroup>

</Project>

就OK了

 

  • net8调用Configuration.Binder的Get方法

项目配置

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

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net8.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UseWPF>true</UseWPF>
  </PropertyGroup>


  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
  </ItemGroup>

</Project>

调用方法 Microsoft.Extensions.Configuration.ConfigurationBinder.Get扩展方法

微软回复:https://developercommunity.visualstudio.com/t/net6-wpf-publish-failed-when-include-hos/10552458?page=31&pageSize=15&sort=active&openOnly=false&closedOnly=false&topics=test-plans

发布也一样: net8.0-windows win-x64

解决办法:增加配置

<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Microsoft.Extensions.Configuration.Binder.SourceGeneration</InterceptorsPreviewNamespaces>

 

  • 文件重复

如果多个项目里有相同名字的静态文件,使用拷贝带到项目中

 会导致发布错误,需要改成只有一个项目有此文件

 

posted @ 2024-01-13 16:38  咖喱gg  阅读(228)  评论(0编辑  收藏  举报