dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.75k stars 1.07k forks source link

`error MC1000: Unknown build error` when using reference assembly and XAML #19884

Open Alovchin91 opened 3 years ago

Alovchin91 commented 3 years ago

I'm facing the following error when building a specifically setup project:

1>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(268,9): error MC1000: Unknown build error, 'Could not load type 'SharpSvn.Implementation.SvnLibraryAttribute' from assembly 'SharpSvn, Version=1.14001.54.0, Culture=neutral, PublicKeyToken=d729672594885a28' because the method '.ctor' has no implementation (no RVA).'

This is an SDK style project that has a PackageReference to SharpSvn which includes a reference assembly built by refasmer: https://github.com/AmpScm/SharpSvn/blob/6074f8d75e9a33878c3b7c91be3f943dbc0986ec/nuspec/build.cmd#L31

Here's what the project file looks like:

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

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <Platforms>x64</Platforms>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
    <Reference Include="System.Xaml" />
    <Reference Include="WindowsBase" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="SharpSvn" Version="1.14001.54" />
  </ItemGroup>

  <ItemGroup>
    <Page Include="Page1.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </Page>
  </ItemGroup>

</Project>

The reason why I'm posting this issue here (and not in SharpSvn or refasmer repos) is because if I change the project file as follows:

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

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <Platforms>x64</Platforms>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
    <Reference Include="System.Xaml" />
    <Reference Include="WindowsBase" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="SharpSvn" Version="1.14001.54" />
  </ItemGroup>

</Project>

-- it builds without an issue.

It seems to me that there is something in Microsoft.WinFx.targets that is different for XAML files when built with UseWPF = true and with Generator = MSBuild:Compile.

Please find a repro sample attached.

SharpSvnBugRepro.zip

sfoslund commented 3 years ago

I'm not familiar with the <Generator>MSBuild:Compile</Generator> syntax. @BenVillalobos @Forgind could this be a MSBuild issue?

Alovchin91 commented 3 years ago

I suppose this is some kind of an older syntax since these projects have been converted from non-SDK style. UseWPF syntax could also work for us, but I never saw it being used in .NET FX (net472) projects.