Open yukw777 opened 1 year ago
Can you say a bit more about what kind of project you are trying to run? Is it a .NET framework project? Check that your .csproj is in the "new" SDK style: https://stackoverflow.com/questions/63055430/how-to-create-an-sdk-style-net-framework-project-in-vs
It’s a multi-framework project that targets net472 and net7.0. This error only happens for net472. Here’s a snippet of my csproj file (which I believe is already the new sdk style):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net472;net7.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
<SelfContained>true</SelfContained>
<Platforms>x64</Platforms>
</PropertyGroup>
…
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
<Content Include="$(NuGetPackageRoot)/microsoft.psi.media.windows.x64/0.18.72.1-beta/lib/net472/Microsoft.Psi.Media_Interop.Windows.x64.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
…
Note that instead of using PublishSingleFile for net472, I use Costra.Fody.
When I try to run my project, I get the following error:
The workaround I've found is to include the following in my .csproj file:
Adding the following didn't work:
When I use
dotnet run
to run my project, it fails with the same error the first time, and it starts working again the second time. I'm assumingdotnet run
somehow copies the dll over on the first run. Not sure why it fails every time on Visual Studio without the workaround above.Any pointers would be appreciated!