Search code examples
wpfvisual-studio-2013msbuildprojects-and-solutions

wpf prism mef visual studio project file


I've got a WPF/Prism 4.0/MEF(MVVM) application. Everything runs/loads fine, except when I Change the Project file.

The Version that works contains the following, but the Project browser does not load the *.cs code-behind files into the tree hierarchy correctly. The code-behind files are inserted at the same tree level as the *.xaml files:

<ItemGroup>
   <Compile Include="Models\MainProjectDataModel.cs" />
   <Compile Include="ViewModels\MainProjectDataViewModel.cs" />
   <Compile Include="ViewModels\MainWindowViewModel.cs" />
   <Compile Include="Views\MainMenuView.xaml.cs" />
   <Compile Include="Views\MainProjectDataView.xaml.cs" />
   <Compile Include="Views\MainToolbarView.xaml.cs" />
   <Page Include="Views\MainMenuView.xaml">
     <Generator>MSBuild:Compile</Generator>
     <SubType>Designer</SubType>
   </Page>
   <Page Include="Views\MainProjectDataView.xaml">
     <Generator>MSBuild:Compile</Generator>
     <SubType>Designer</SubType>
   </Page>
   <Page Include="Views\MainToolbarView.xaml">
     <Generator>MSBuild:Compile</Generator>
     <SubType>Designer</SubType>
   </Page>
</ItemGroup>

This Version loads the tree correctly, but mangles something during compile/generation - so that the regions associated with the menu/toolbar/data are not found:

<ItemGroup>
   <Compile Include="Models\MainProjectDataModel.cs" />
   <Compile Include="ViewModels\MainProjectDataViewModel.cs" />
   <Compile Include="ViewModels\MainWindowViewModel.cs" />
</ItemGroup>

<ItemGroup>
   <Page Include="Views\MainMenuView.xaml">
     <Generator>MSBuild:Compile</Generator>
     <SubType>Designer</SubType>
   </Page>
   <Page Include="Views\MainProjectDataView.xaml">
     <Generator>MSBuild:Compile</Generator>
     <SubType>Designer</SubType>
   </Page>
   <Page Include="Views\MainToolbarView.xaml">
     <Generator>MSBuild:Compile</Generator>
     <SubType>Designer</SubType>
   </Page>
</ItemGroup>    

I've tried adding '<DependentUpon>' Markup to the compiled files (following the generated code for app.xaml and Shell.xaml, but the tree is still incorrectly filled.

<Compile Include="Views\MainMenuView.xaml.cs">
  <DependentUpon>Views\MainMenuView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\MainProjectDataView.xaml.cs">
  <DependentUpon>Views\MainProjectDataView</DependentUpon>
</Compile>
<Compile Include="Views\MainToolbarView.xaml.cs"> 
  <DependentUpon>Views\MainToolbarView.xaml</DependentUpon>
</Compile>
<Page Include="Views\MainMenuView.xaml">
  <Generator>MSBuild:Compile</Generator>
  <SubType>Designer</SubType>
</Page>
<Page Include="Views\MainProjectDataView.xaml">
  <Generator>MSBuild:Compile</Generator>
  <SubType>Designer</SubType>
</Page>
<Page Include="Views\MainToolbarView.xaml">
  <Generator>MSBuild:Compile</Generator>
  <SubType>Designer</SubType>
</Page>

Naturally, this is an annoyance, not a real bug - but what gives? I've found documentation on MSBuild - hopefully this is the right place to look. Am I right? There's lots of stuff there and I'd rather not slog through it all right now - does anyone know where in the docs I should look or what's going on here?


Solution

  • Remove the Views\ part of the DependentUpon node:

    <Compile Include="Views\MainToolbarView.xaml.cs"> 
      <DependentUpon>MainToolbarView.xaml</DependentUpon>
    </Compile>
    

    The Include requires a path relative to the project file, and the DependentUpon is a path relative to the .cs file - so in virtually all cases these files will be beside each other so no extra path nomenclature is required.