Warning - The parent file 'Views\file.xaml', for the file 'Views\file.xaml.cs' cannot be found in the project file

StackOverflow https://stackoverflow.com/questions/21531950

Question

First of all, I have looked at the other related posts on StackOverflow.com and changing the path in the csproj file didn't make any difference in this warning as you will see below. Reference: why do i get this warning .cs file cannot be found in project file And also: How can I connect xaml and xaml.cs files

I've got what amounts to MainWindow.xaml and MainWindow.xaml.cs. I decided to move both of these into the Views folder because I didn't like my main window view floating around with the csproj file, and App.xaml/App.xaml.cs files.

Basically:

Views/MainWindow.xaml

Views/MainWindow.xaml.cs

So my first question: Is this not allowed? Are we required to have the MainWindow.xaml & MainWindow.xaml.cs files to be in the same location as the csproj file?

Second Question: If not, then what else am I missing because I'm pretty sure I got all the paths set correctly?

<Page Include="Views\TimersHost.xaml">
  <Generator>MSBuild:Compile</Generator>
  <SubType>Designer</SubType>
</Page>
  <Compile Include="Views\TimersHost.xaml.cs">
  <DependentUpon>Views\TimersHost.xaml</DependentUpon>
  <SubType>Code</SubType>
</Compile>

I even put them in the same tags so there is no room for confusion on the part of the compiler, but it is still complaining with a warning: The parentfile, 'Views\TimersHost.xaml', for file 'Views\TimersHost.xaml.cs' cannot be found in the project file.

The warning actually seems to indicate that its the parent of the MainWindow.xaml is what cannot be found, but technically there is no parent, unless it is referring to the csproj file itself, which is why I ask if we are required to have the MainWindow.xaml be in the same location as the csproj file.

For instance it was mentioned in this post that the MainWindow.xaml should be put in the Views folder, which is what I'm trying to do: Project structure for MVVM in WPF

So I'm pretty sure that I'm just missing something, but have no idea what it might be or where to even begin looking. Even my StartupUri in the App.xaml is set correctly to point to the file:

<Application 
x:Class="TimersXP.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Views/TimersHost.xaml"
/>

Maybe in the TimersHost.xaml file I need to specify the path for the class? x:Class="Views/TimersXP.TimersHost"....No that doesn't make sense, and doesn't work anyways.

It's an open-source project so here is the full csproj file source: http://timersxp.codeplex.com/SourceControl/latest#VS2013/TimersXP/TimersXP.csproj (latest version is current)

Was it helpful?

Solution

Not having tested this, my answer is speculative. However:

I would imagine that the DependentUpon path is a path relative to the current file - not to the project root as you have assumed. Try changing it to this:

<DependentUpon>TimersHost.xaml</DependentUpon>

OTHER TIPS

For Googlers who can't get rid of the warning without build issues: This is a known bug in Visual Studio still present as of v17.1. Unfortunately there's nothing much that can be done about it at this point.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top