Background
Attempting to build a .Net core application, but ran into a blocking error.
Request
So to compile a .Net Core application, from the command line, I will simply navigate to the solution folder and issue a “dotnet build” command.
Error
Error Messages
Textual
- error CS0101: The namespace [project] already contains a definition
- error CS0111: Type [class-name] already defines a member called [member-function] with the same parameter types
Image
TroubleShooting
Find matching text
Findstr
Syntax
findstr [pattern] [filename]
Sample
findstr /P /s "ConsoleApp1" *.cs | findstr /v obj
Output
Output – Textual
>findstr /P /s "ConsoleApp1" *.cs | findstr /v obj deprecate\20200710.0437PM\Program.cs:namespace ConsoleApp1 Program.cs:namespace ConsoleApp1
Output – Image
Explanation
There are two files that have ConsoleApp1. Our actual file and a backup/deprecated file.
Remediation
Project File ( csproj )
Please edit your project file ( .csproj) and exclude the unneeded files.
Outline
- Add Section :- ItemGroup
- Add Items
- Add Item:- Compile
- Add Item:- EmbeddedResource
- Add Item:- None
Original
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.1</TargetFramework> </PropertyGroup> </Project>
Revised
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.1</TargetFramework> </PropertyGroup> <ItemGroup> <Compile Remove="deprecate\**" /> <EmbeddedResource Remove="deprecate\**" /> <None Remove="deprecate\**" /> </ItemGroup> </Project>
Reference
- Microsoft
- Docs > .NET > .NET Core > guide > Tools
- dotnet command
Link
- dotnet command
- Docs > .NET > .NET Core > guide > Tools
You must be logged in to post a comment.