CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

Targets file with invalid target names generated. Error when consumed from C++/WinRT app

Open Psychlist1972 opened this issue 2 years ago • 2 comments

C#/WinRT, .NET 7 component created. When consumed by a C++/WinRT app, I get MSB5016 on build:

Severity Code Description Project File Line Suppression State Error MSB5016 The name "Microsoft.Windows.MidiAddAuthoredWinMDReference" contains an invalid character ".". VerifyServiceIsRunning D:\peteb\Documents\GitHub\microsoft\midi\get-started\samples\cpp-winrt\VerifyServiceIsRunning\packages\Microsoft.Windows.Midi.0.1.0\build\Microsoft.Windows.Midi.targets 25

Here's the generated targets file parts with the error:

  <!-- Add the WinMD file as a reference of the native app so a projection gets made -->
  <Target Name="Microsoft.Windows.MidiAddAuthoredWinMDReference" Outputs="@(Reference)">
    <ItemGroup Condition="'$(TargetFramework)' == 'native' OR '$(TargetFramework)' == ''">
      <Reference Include="$(MSBuildThisFileDirectory)..\lib\net*\winmd\*.winmd">
        <IsWinMDFile>true</IsWinMDFile>
        <Implementation>WinRT.Host.dll</Implementation>
      </Reference>
    </ItemGroup>
    <ItemGroup Condition="'$(TargetFramework)' != 'native' AND '$(TargetFramework)' != ''">
      <ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)..\lib\net*\winmd\*.winmd" />
    </ItemGroup>
  </Target>
  <!-- Make sure the runtime assets are available to the app -->
  <Target Name="Microsoft.Windows.MidiCopyAuthoringDlls" Condition="'$(TargetFramework)' == 'native' OR '$(TargetFramework)' == ''" Outputs="@(ReferenceCopyLocalPaths)">
    <ItemGroup>
      <ReferenceCopyLocalPaths Include="@(HostingAssets)" />
    </ItemGroup>
  </Target>

If I manually change those names (and the ones at the top which refer to them) to replace . with _. that error goes away. But I have to do that each time I update the nuget package reference, or create a new project.

Visual Studio 2022 version 17.3.0 Preview 4.0 .NET 7 preview

Psychlist1972 avatar Jul 30 '22 00:07 Psychlist1972

When consumed from a C# desktop app, I get this:

Severity Code Description Project File Line Suppression State Error Project "C:\Users\peteb.nuget\packages\microsoft.windows.midi\0.1.0\buildTransitive\Microsoft.Windows.Midi.targets" was not imported by "D:\peteb\Documents\GitHub\microsoft\midi\get-started\samples\csharp-net\VerifyServiceIsRunningCsNet\obj\VerifyServiceIsRunningCsNet.csproj.nuget.g.targets" at (4,5), due to the file being invalid. VerifyServiceIsRunningCsNet C:\Users\peteb.nuget\packages\microsoft.windows.midi\0.1.0\buildTransitive\Microsoft.Windows.Midi.targets 4

Same manual replace fix worked here as well.

In UWP (see bug 1230) there's no opportunity to fix the file. I suspect that's the same issue, however.

Psychlist1972 avatar Jul 30 '22 01:07 Psychlist1972

@Psychlist1972 - Do you see the same issue with a NET6 component?

AdamBraden avatar Aug 10 '22 16:08 AdamBraden