Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# project file - Why doesn't it represent what's in my project?

I am trying to understand the contents of a .csproj file after I converted from PCL to a .NET shared. Here is an example and some questions:

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

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="3.1.0.583944" />
    <PackageReference Include="sqlite-net-pcl" Version="1.4.118" />
    <PackageReference Include="Syncfusion.Xamarin.SfChart" Version="16.2.0.42" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Views\" />
    <Folder Include="Views\Settings\Pages\" />
    <Folder Include="Views\Home\PopUp\" />
    <Folder Include="Views\Help\Cards\" />
  </ItemGroup>

Can someone explain to me why only certain folders appear above even though my project has many more folders

  <ItemGroup>
    <EmbeddedResource Remove="Views\Cards\Category\CategoriesPage.xaml" />
    <EmbeddedResource Remove="Views\Cards\Templates\LinkTextCell.xaml" />
    <EmbeddedResource Remove="Views\Cards\Templates\SwitchViewCell.xaml" />
    <EmbeddedResource Remove="Views\Home\Dictionary.xaml" />
  </ItemGroup>

Can someone explain what all these Remove lines do / mean?

  <ItemGroup>
    <None Include="Views\Cards\Cards.xaml" />
    <None Include="Views\Cards\Category\CategoriesPage.xaml" />
    <None Include="Views\Cards\Category\CategoryViewCell.xaml" />
    <None Include="Views\Cards\Templates\LinkTextCell.xaml" />
    <None Include="Views\Cards\Templates\SwitchViewCell.xaml" />
    <None Include="Views\MainPage.xaml" />
    <None Include="Views\MainPage.xaml" />
    <None Include="Views\MainPage.xaml" />
    <None Include="Views\MainPage.xaml" />
  </ItemGroup>

Can someone explain why the MainPage might appear four times? Is it needed more than once, is it needed at all? There are many files that are not in the list of Includes? If only half are there then why is it?

  <ItemGroup>
    <Compile Update="Views\MainPage.xaml.cs">
      <DependentUpon>MainPage.xaml</DependentUpon>
    </Compile>
    <Compile Update="Views\Home\HomePage.xaml.cs">
      <DependentUpon>HomePage.xaml</DependentUpon>
    </Compile>
    <Compile Update="Views\Cards\Category\CategoryViewCell.xaml.cs">
      <DependentUpon>CategoryViewCell.xaml</DependentUpon>
    </Compile>
  </ItemGroup>
</Project> 

I understand that some views depend on others but I have many more of these and yet it only shows the relationship for three. Why could this be?

Can I just remove all these entries from the project file as there seems to be not much similarity between the project file and the folders / files in the project?

like image 393
Alan2 Avatar asked Jul 10 '18 14:07

Alan2


1 Answers

The new .csproj format has some basic changes to simplify the file. Now by default all .cs (or .vb if you're doing VB.Net) files are included. See here for more information.

The reason your file is explicitly including some files and folders is because you've probably edited the file properties at some point.

The Remove lines are there to allow files to be part of your project structure but not compiled or embedded automatically.

As for why MainPage.xaml appears multiple times, I have no idea. Either a bug in Visual Studio has added them, or perhaps a source control merge conflict. Either way, those duplicate lines are redundant and can be removed.

like image 165
DavidG Avatar answered Oct 23 '22 18:10

DavidG