Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DotNet Core .csproj code files as child items

I am migrating an old .NET Framework csproj to dotnet core. What is the dotnet core equivalent of this:

<Compile Include="ServiceHost.Designer.cs">
  <DependentUpon>ServiceHost.cs</DependentUpon>
</Compile>

I tried:

<ItemGroup>
    <Compile Include="ServiceHost.Designer.cs">
        <DependentUpon>ServiceHost.cs</DependentUpon>
    </Compile>
</ItemGroup>

But I got this error:

Duplicate 'Compile' items were included. The .NET SDK includes 'Compile' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultCompileItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: 'ProjectInstaller.Designer.cs'; 'ServiceHost.Designer.cs' TestWindowsService C:\Program Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.targets

like image 929
Zeus82 Avatar asked Jan 24 '18 14:01

Zeus82


People also ask

How do I open a .csproj file?

How to open a CSPROJ file. CSPROJ files are are meant to be opened and edited in Microsoft Visual Studio (Windows, Mac) as part of Visual Studio projects. However, because CSPROJ files are XML files, you can open and edit them in any text or source code editor.

What is a .csproj file?

What is a CSProj file? Files with CSPROJ extension represent a C# project file that contains the list of files included in a project along with the references to system assemblies.

Where is .csproj file located?

csproj files (WebApi is the name of my project). It is located as expected in the root of the project.


1 Answers

Since the items are included by default, you need to use Update instead of Include if you only want to modify the items that need this update and not list every cs file individually:

<ItemGroup>
    <Compile Update="ServiceHost.Designer.cs">
        <DependentUpon>ServiceHost.cs</DependentUpon>
    </Compile>
</ItemGroup>
like image 93
Martin Ullrich Avatar answered Oct 05 '22 14:10

Martin Ullrich