Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does .net core project know which files to include while building

I observed there is a difference in .csproj file in .Net standard and .Net Core.
In .Net projects all files(.cs,.js etc) were included in .csproj file for each project. e.g:

<Compile Include="ViewModel\LiveViewViewModel.cs" />
<Compile Include="ViewModel\RegistrationViewModel.cs" />
<Compile Include="Views\LiveView.xaml.cs">
  <DependentUpon>LiveView.xaml</DependentUpon>
</Compile>

But if i see the new .Net Core .csproj file, there is no mention of any .cs/.js or any file.
I am very curious to understand how does .net core projects include files while being compiled.

like image 211
Nasim Avatar asked May 11 '18 09:05

Nasim


1 Answers

They are now coming from msbuild definition files imported via the Microsoft.NET.Sdk MSBuild sdk and use wildcards to specify a search pattern based off the project file's location.

The (simplified) equivalent would be if you wrote

<Compile Include="**\*.cs" />

into the project file, which has been supported by msbulid for long time but didn't work well with Visual Studio tooling. The new project system can deal with wildcards much better and then add the appropriate <Compile Remove".."/> or Update=".." definition if you exclude some files or change metadata in the properties windows.

The source code for the default items be found here as well as some extra definitions brought in by the web-sdk for ASP.NET Core projects here.

like image 164
Martin Ullrich Avatar answered Oct 21 '22 06:10

Martin Ullrich