Module 1: Project Structure & .csproj File

Mohammad Zubair 0
Logo

Console Application বা যেকোনো .NET Project তৈরি হলে Visual Studio বা CLI স্বয়ংক্রিয়ভাবে কিছু ফোল্ডার ও ফাইল তৈরি করে দেয়। এগুলোই হলো আপনার প্রজেক্টের মূল কাঠামো।

এই কাঠামো বুঝে কাজ করলে—
✔ কোড অর্গানাইজেশন সহজ হয়
✔ Build/debug সহজ হয়
✔ বড় প্রজেক্ট নিয়ে কাজ করা সহজ হয়
✔ Dependency ও configuration বুঝতে সুবিধা হয়


1. একটি Console Project Structure কেমন হয়?

সাধারণত নতুন Console Application তৈরি করলে আপনি এরকম একটি ফোল্ডার স্ট্রাকচার দেখবেন:

MyApp/
 ├── bin/
 ├── obj/
 ├── Program.cs
 └── MyApp.csproj

এখন প্রতিটি অংশ আলাদাভাবে ব্যাখ্যা করছি—


2. Program.cs

এই ফাইল হলো C# Console Application-এর “Entry Point”।
এখানেই আপনার কোড শুরু হয়।

.NET 6+ এ “Top-level statements” ব্যবহারের কারণে Main method না লিখেও কোড শুরু হয়।

উদাহরণ:

Console.WriteLine("Hello World!");

এর মানে:
প্রজেক্ট রান করলে CLR প্রথমে Program.cs ফাইলটি পড়ে এবং এখান থেকেই এক্সিকিউশন শুরু হয়।


3. bin/ Folder (Build Output)

bin/ ফোল্ডারটি হচ্ছে Build Output Directory

এখানে থাকে—

  • অ্যাপের কম্পাইল করা DLL

  • EXE (Windows এ)

  • Dependencies

  • Debug/Release ভার্সন অনুযায়ী আউটপুট

উদাহরণ:

bin/
 ├── Debug/
 │    └── net8.0/
 │         └── MyApp.dll
 └── Release/
      └── net8.0/
           └── MyApp.dll

গুরুত্ব:
এই ফোল্ডারের ফাইলগুলোই আপনি সার্ভার বা ক্লাউডে ডিপ্লয় করবেন।


4. obj/ Folder (Temporary Build Data)

obj/ হলো temporary build ফোল্ডার যেখানে MSBuild বিল্ড প্রসেসের অস্থায়ী ফাইল রাখে।

এখানে থাকে—

  • Project.assets.json

  • Generated code

  • Assembly info

  • Intermediate IL files

উদাহরণ:

obj/
 └── Debug/
       └── net8.0/
            └── MyApp.AssemblyInfo.cs

গুরুত্ব:
এটি build pipeline-এর জন্য জরুরি, ম্যানুয়ালি পরিবর্তন করা যাবে না।


5. .csproj File — প্রজেক্টের হৃদয়

.csproj হলো একটি XML ফাইল যেখানে আপনার পুরো প্রজেক্টের কনফিগারেশন থাকে।

এখানে উল্লেখ করা হয়:

  • কোন .NET Framework ব্যবহার হচ্ছে

  • NuGet dependencies

  • Build configuration

  • Nullable settings

  • Output type (Exe / Library)

  • Version settings

  • File include/exclude rules

  • Runtime identifiers

  • Publish settings


6. একটি Console Application-এর সাধারণ .csproj উদাহরণ

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
</Project>

এখন প্রতিটি অংশ ব্যাখ্যা করা হলো—


7. PropertyGroup — Project Settings Container

<PropertyGroup> ট্যাগের মধ্যে প্রজেক্টের মূল সেটিংগুলো থাকে।

✔ OutputType

<OutputType>Exe</OutputType>

এটি নির্ধারণ করে:

  • Exe → Console/Desktop App (রানযোগ্য)

  • Library → Class Library (রানযোগ্য নয়, শুধু ব্যবহার হবে অন্য প্রজেক্টে)

✔ TargetFramework

<TargetFramework>net8.0</TargetFramework>

আপনার প্রজেক্ট কোন .NET Runtime ব্যবহার করবে তা নির্ধারণ করে।

উদাহরণ:

  • net8.0

  • net7.0

  • net6.0

  • netstandard2.1 (শেয়ার্ড লাইব্রেরির জন্য)

  • net48 (.NET Framework specific)

✔ Nullable

<Nullable>enable</Nullable>

Null safety চালু করে। এটি industry standard এবং highly recommended।

✔ ImplicitUsings

<ImplicitUsings>enable</ImplicitUsings>

System, System.Linq এর মতো common namespaces স্বয়ংক্রিয়ভাবে include করে।


8. NuGet package যোগ করলে কী হয়?

ধরুন আপনার প্রজেক্টে Newtonsoft.Json লাগবে।

কমান্ড:

dotnet add package Newtonsoft.Json

তখন csproj ফাইল নিজে থেকে আপডেট হবে:

<ItemGroup>
  <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

PackageReference-ই ঠিক করে আপনি কোন NuGet লাইব্রেরি ব্যবহার করছেন।


9. একাধিক PropertyGroup থাকতে পারে

আপনি চাইলে Debug এবং Release এর আলাদা সেটিং রাখতে পারেন:

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<DefineConstants>DEBUG</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
<Optimize>true</Optimize>
</PropertyGroup>


10. File Include / Exclude Control

আপনি কোন ফাইল বিল্ডে যাবে বা যাবে না সেটাও এখানে নিয়ন্ত্রণ করতে পারেন:

<ItemGroup>
<Compile Remove="OldFiles\*.cs" />
<None Include="data.json" CopyToOutputDirectory="Always" />
</ItemGroup>

11. Runtime Identifier (RID) দিলে Self-contained Executable তৈরি হয়

<PropertyGroup>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>

এর ফলে:
✔ runtime-সহ portable EXE তৈরি হবে
✔ আলাদা .NET runtime লাগবে না


সারসংক্ষেপ (সহজ ভাষায়)

  • Project Structure আপনাকে দেখায় আপনার কোড কোথায় আছে এবং কীভাবে বিল্ড হচ্ছে।

  • Program.cs হচ্ছে main file

  • bin/ = final output

  • obj/ = temporary build files

  • .csproj = প্রজেক্টের কনফিগারেশন ফাইল

  • NuGet packages, framework version, build rules—সব .csproj-এ থাকে


Mohammad Zubair

I'm Mohammad Zubair, a passionate software engineer working in the dynamic world of IT. Currently, I'm proud to be a part of HawarIT, a thriving Dutch-Bangladeshi joint venture company, where I contribute my expertise and enthusiasm to the field of software engineering.

Leave a Reply

Your email address will not be published. Required fields are marked *