我正在try 将.NET Core 6 Blazor服务器项目发布到Portainer.我可以在Debug中很好地构建和运行项目,然而,当我try 发布或发布项目时,构建失败了,并给出了以下信息.

错误MSB4803:不支持任务"ResolveComReference". MSBuild的.NET核心版本.请使用.NET框架版本的 MSBuild.有关更多详细信息,请参见https://aka.ms/msbuild/MSB4803. [/src/Necon/Necon.csproj]

整个构建try 的输出为:

------
 > [build 7/7] RUN dotnet build "Necon.csproj" -c Release -o /app/build:
#15 2.489   All projects are up-to-date for restore.
#15 3.000 /usr/share/dotnet/sdk/6.0.408/Microsoft.Common.CurrentVersion.targets(2927,5): error MSB4803: The task "ResolveComReference" is not supported on the .NET Core version of MSBuild. Please use the .NET Framework version of MSBuild. See https://aka.ms/msbuild/MSB4803 for further details. [/src/Necon/Necon.csproj]
#15 3.007 
#15 3.007 Build FAILED.
#15 3.007 
#15 3.007 /usr/share/dotnet/sdk/6.0.408/Microsoft.Common.CurrentVersion.targets(2927,5): error MSB4803: The task "ResolveComReference" is not supported on the .NET Core version of MSBuild. Please use the .NET Framework version of MSBuild. See https://aka.ms/msbuild/MSB4803 for further details. [/src/Necon/Necon.csproj]
#15 3.007     0 Warning(s)
#15 3.007     1 Error(s)
#15 3.007 
#15 3.007 Time Elapsed 00:00:01.90
------
WARNING: buildx: git was not found in the system. Current commit information was not captured by the build
Dockerfile:14

我在谷歌上搜索的大部分时间都指向这个答案error : MSB4803: The task "ResolveComReference" is not supported on the .NET Core version of MSBuild,然而它已经有近3年的历史了.我也试过this article次,但没有成功.

我的被告栏文件是:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Necon/Necon.csproj", "Necon/"]
RUN dotnet restore "Necon/Necon.csproj"
COPY . .
WORKDIR "/src/Necon"
RUN dotnet build "Necon.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Necon.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Necon.dll"]

Necon.csproj先生是:

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

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UserSecretsId>8ac9eb75-ec3e-42b0-b702-405a8e375b34</UserSecretsId>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <EnableSdkContainerSupport>true</EnableSdkContainerSupport>
  </PropertyGroup>

  <ItemGroup>
    <COMReference Include="DecklinkPublicLib">
      <WrapperTool>tlbimp</WrapperTool>
      <VersionMinor>0</VersionMinor>
      <VersionMajor>1</VersionMajor>
      <Guid>1469d378-8829-4ff0-9b3b-07dd5b16f3cb</Guid>
      <Lcid>0</Lcid>
      <Isolated>false</Isolated>
      <EmbedInteropTypes>true</EmbedInteropTypes>
    </COMReference>
    <COMReference Include="BMDSwitcherAPI">
      <WrapperTool>tlbimp</WrapperTool>
      <VersionMinor>0</VersionMinor>
      <VersionMajor>1</VersionMajor>
      <Guid>8a92b919-156c-4d61-94ef-03f9be4004b0</Guid>
      <Lcid>0</Lcid>
      <Isolated>false</Isolated>
      <EmbedInteropTypes>true</EmbedInteropTypes>
    </COMReference>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="6.0.13" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.13" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.13" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.13" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.13">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.11" />
    <PackageReference Include="MudBlazor" Version="6.1.8" />
  </ItemGroup>

</Project>

我的dockerIgnore文件是:

**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md

My publish settings are: enter image description here

推荐答案

我想这个问题和下面的COMReference有关,我研究过,DecklinkPublicLib似乎可以在Linux上使用,但BMDSwitcherAPI不能.

这样您就可以在.csproj文件中对其进行注释,并try 一下.

Tips个 在注释之后,您需要try 在您的本地编译它,然后部署它.

Workaround

使用Windows平台,而不是Linux.

 <COMReference Include="DecklinkPublicLib">
  <WrapperTool>tlbimp</WrapperTool>
  <VersionMinor>0</VersionMinor>
  <VersionMajor>1</VersionMajor>
  <Guid>1469d378-8829-4ff0-9b3b-07dd5b16f3cb</Guid>
  <Lcid>0</Lcid>
  <Isolated>false</Isolated>
  <EmbedInteropTypes>true</EmbedInteropTypes>
</COMReference>
<COMReference Include="BMDSwitcherAPI">
  <WrapperTool>tlbimp</WrapperTool>
  <VersionMinor>0</VersionMinor>
  <VersionMajor>1</VersionMajor>
  <Guid>8a92b919-156c-4d61-94ef-03f9be4004b0</Guid>
  <Lcid>0</Lcid>
  <Isolated>false</Isolated>
  <EmbedInteropTypes>true</EmbedInteropTypes>
</COMReference>

Csharp相关问答推荐

自定义JsonEditor,用于将SON序列化为抽象类

ASP.NET MVC购物车数量更新并从购物车中删除项目

错误401未授权ASP.NET Core.使用JWT创建身份验证/授权

Elasticsearch:当我try 使用c#将嵌套对象添加到filter中时出现问题

如果存在对CodeAnalysis.CSharp的引用,则不能引用netStandard2.0库

Polly v8—使用PredicateBuilder重试特定的状态代码

Blazor-从数据库内部服务器提取错误

如何使用C#Interop EXCEL创建度量衡

DbContext-传递自定义配置选项

如何使用.NET6WPF打印车票?

为什么我可以用硬编码的集合而不是变量来设置没有setter的IList属性的值?

VS 2022与VS 2019:如何/为什么创建额外的任务?

WinUI 3中DoubleCollection崩溃应用程序类型的依赖属性

我的命名管道在第一次连接后工作正常,但后来我得到了System.ObjectDisposedException:无法访问关闭的管道

如何使用类似于[SELECT*FROM&Q;&Q;WHERE&Q;]SQL查询的System.Data.Entity创建查询?

Visual Studio,Docker容器-容器调用:连接被拒绝

为什么Swashbakle/Swagger在参数中包含变量名?

最小API定义的Swagger标头参数

反编译源代码时出现奇怪的字符

如何提高C#中比较大 struct 的性能?