csharp-scripts
ما الذي تفعله
تشغّل هذه المهارة كود C# كتطبيق من ملف واحد بأداة سطر أوامر .NET، فتستطيع اختبار فكرة دون بناء مشروع كامل. وهي مناسبة لمطور يريد تجربة مفهوم C# أو ميزة لغة أو أداة صغيرة بسرعة.
متى تستخدمها
- ✓عندما تريد اختبار مفهوم أو واجهة برمجية أو ميزة لغة في C# بسرعة.
- ✓عندما تريد تشغيل أداة صغيرة بـC# من ملف واحد أو عدة ملفات.
- ✓عندما تريد تجربة منطق C# قبل إضافته إلى مشروع حقيقي.
رابط المهارة
https://github.com/dotnet/skills/blob/main/plugins/dotnet-advanced/skills/csharp-scripts/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“اكتب ملف C# صغيراً يقرأ ملف CSV ويطبع المجاميع، ثم شغّله دون إنشاء مشروع.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
يتحقق وكيلك من أن SDK لـ.NET مثبت وحديث بما يكفي، ويكتب ملف C#، ويشغّله بأمر dotnet، ويضيف ملفات مساعدة عند الحاجة.
المحتوى التقني (ملف SKILL.md الأصلي)
النص الأصلي من المؤلف، مباشرة من GitHub.
File-Based C# Apps
When to Use
- Testing a C# concept, API, or language feature with a quick file-based app
- Prototyping logic before integrating it into a larger project
- Building a small utility from one entry-point file and a few helper
.csfiles
When Not to Use
- The user asks for a language-agnostic quick script, throwaway computation, or shell/Python/PowerShell-style automation
- The user needs a full project, solution integration, or project references in an existing app
- The user is working inside an existing .NET solution and wants to add code there
- The app is large enough that project structure, build customization, tests, or publish configuration should live in a
.csproj
Inputs
| Input | Required | Description |
|---|---|---|
| C# code or intent | Yes | The code to run, or a description of what the file-based app should do |
Workflow
Step 1: Check the .NET SDK version
Run dotnet --version to verify the SDK is installed and note the full version, including the feature band. File-based apps require .NET 10 or later. #:include, #:exclude, and transitive directive processing require SDK 10.0.300 or later; SDK 10.0.100/10.0.200 builds can run single-file apps but do not support those multi-file directives. If the version is below 10, follow the fallback for older SDKs instead.
Step 2: Write the app file
Create an entry-point .cs file using top-level statements. Place it outside any existing project directory to avoid conflicts with .csproj files.
#!/usr/bin/env dotnet
// hello.cs
Console.WriteLine("Hello from a file-based app!");
var numbers = new[] { 1, 2, 3, 4, 5 };
Console.WriteLine($"Sum: {numbers.Sum()}");
Guidelines:
- Use top-level statements (no
Mainmethod, class, or namespace boilerplate) - Place
usingdirectives at the top of the file (after the#!line and any#:directives if present) - Place type declarations (classes, records, enums) after all top-level statements
Step 3: Run the app
dotnet hello.cs
Builds and runs the file automatically. Cached so subsequent runs are fast. Pass arguments after --:
dotnet hello.cs -- arg1 arg2 "multi word arg"
Step 4: Add directives (if needed)
Place directives at the top of the file (immediately after an optional shebang line), before any using directives or other C# code. All directives start with #:.
#:package — NuGet package references
Specify a version unless the app intentionally uses central package management. Use @* when the latest available package is acceptable (or @*-* for pre-release):
#:package Humanizer@2.14.1
using Humanizer;
Console.WriteLine("hello world".Titleize());
#:property — MSBuild properties
Set any MSBuild property inline. Syntax: #:property PropertyName=Value
#:property AllowUnsafeBlocks=true
#:property PublishAot=false
#:property NoWarn=CS0162
MSBuild expressions and property functions are supported:
#:property LogLevel=$([MSBuild]::ValueOrDefault('$(LOG_LEVEL)', 'Information'))
Common properties:
| Property | Purpose |
|---|---|
AllowUnsafeBlocks=true |
Enable unsafe code |
PublishAot=false |
Disable native AOT (enabled by default) |
NoWarn=CS0162;CS0219 |
Suppress specific warnings |
LangVersion=preview |
Enable preview language features |
InvariantGlobalization=false |
Enable culture-specific globalization |
#:project — Project references
Reference another project by relative path:
#:project ../MyLibrary/MyLibrary.csproj
#:ref — File-based app references
Reference another .cs file as a separate file-based app project when it should compile into a separate assembly instead of being included in the same compilation. Use #:include for ordinary helper files that should share the same assembly as the entry point; use #:ref when you want project-reference-like boundaries.
#:property ExperimentalFileBasedProgramEnableRefDirective=true
#:ref ../Shared/Formatter.cs
Console.WriteLine(Formatter.Title("hello world"));
Guidelines:
- The referenced file is compiled as its own virtual project and added as a project reference.
- If the referenced file is a library without top-level statements, put
#:property OutputType=Libraryin that referenced file. - Members that must be consumed by the referencing app sh
الأسئلة الشائعة
ما إصدار .NET المطلوب؟
تحتاج التطبيقات المكونة من ملف واحد إلى .NET 10 أو أحدث، وبعض خيارات الملفات المتعددة تحتاج إلى تحديث أحدث لـSDK.
هل هي للبرامج النصية بلغات أخرى؟
لا. هي لكود C# و.NET فقط، لا للبرامج النصية العامة.
متى أستخدم مشروعاً كاملاً بدلاً منها؟
استخدم مشروعاً كاملاً للتطبيقات الكبيرة التي تحتاج إلى إعدادات بناء أو اختبارات أو نشر.
التفاصيل
الوصف الأصلي من المؤلف
Run file-based C# apps with the .NET CLI when the user explicitly wants C#/.NET code without creating a project. Use for C# language/API experiments, one-file C# apps, small multi-file C# apps composed with `#:include`/`#:exclude`, or C# file-based apps linked with `#:ref`. Do not use for language-agnostic throwaway scripts, generic computations, Python/PowerShell-style automation, full projects, or existing app integration.
repo: dotnet/skills
الشعبية
- نجوم GitHub
- 5.8k
- الترتيب
- #14554
- الترخيص
- MIT
- آخر تحديث
- 2/11/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
create-custom-agent
5.8kيساعد وكيلك على إنشاء ملفات وكلاء مخصصين لـVS Code، لكل منهم أدواته وتعليماته وتسليماته إلى وكلاء آخرين.
create-skill
5.8kيساعد وكيلك على إنشاء مهارة وكيل جديدة باسم صالح ووصف محفّز واضح وملف SKILL.md يتبع المعيار.
dotnet-pinvoke
5.8kيساعد وكيلك على استدعاء مكتبات C أو C++ الأصلية من .NET بشكل صحيح، مع التوقيعات ومعالجة النصوص والذاكرة والمقابض الآمنة.
nuget-trusted-publishing
5.8kيساعد وكيلك على إعداد النشر الموثوق لـNuGet من GitHub Actions، فتُنشر الحزم برموز قصيرة العمر بدلاً من مفاتيح API المخزنة.
مهارات مشابهة
diffs
394kيتيح لوكيلك إنتاج فرق تعديلات حقيقي يمكن مشاركته، كرابط عرض أو ملف صورة، بدلاً من ملخص مكتوب يدوياً.
coding-agent
394kيساعد وكيلك على تسليم مهمة برمجة كبيرة إلى Codex أو Claude Code أو OpenCode كعامل في الخلفية، ثم متابعة تقدمها.
gh-issues
394kيساعد وكيلك على إيجاد مشكلات GitHub واختيار ما ستعمل عليه، وفتح طلبات سحب بالإصلاحات، ومتابعة تعليقات المراجعة.