Visual Studio 2019 Test project and error CS0006

  • Thread starter Thread starter CelesteBlanca10
  • Start date Start date
C

CelesteBlanca10

Guest
I think this is one of the strange ones, as I cannot reproduce this on a small demo project, but I still need to fix somehow.

I have an existing WPF project that I am trying to add unit tests to, so I added a Test project to it, referenced the WPF assembly and wrote my tests. When I build it, I receive the notorious CS0006 error as so:

Error CS0006 Metadata file 'C:\Dev\...\WPF_Reader\bin\x64\Release\WPF_Reader.exe' could not be found

Googling this error brings up tons of posts and solutions, but in my case, the reason for this is that the WPF project has a PostBuild event that just renames the WPF exe file, like so:

if $(ConfigurationName) == Release (
move /y WPF_Reader.exe NewName.exe
move /y WPF_Reader.exe.config NewName.exe.config
del *.pdb
)

If I don't run this event, all is good.

So 2 questions here:

  1. Why does the test project care about the name of the executable? The dependency on this project is fine, VS can find all of my types, no compilation errors.
  2. Any ideas how to get around this strange problem?


The test project *.csproj looks like so:

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

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net472</TargetFrameworks>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
<PackageReference Include="Moq" Version="4.14.7" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\WPF_Reader\WPF_Reader.csproj" />
</ItemGroup>

</Project>

Continue reading...
 
Back
Top