كيفية القيام بما يلي: تحديد الملفات المراد بنية
When you بنية a مشروع that يحتوي على several ملفات, you can قائمة each file separately في the ملف مشروع, أو you can استخدم أحرف البدل إلى تضمين الجميع the ملفات في واحد الدليل أو a nested التعيين of directories.
Specifying Inputs
عناصر represent the inputs for a بنية. For المزيد معلومات تشغيل عناصر, see عناصر MSBuild.
إلى مُضمن ملفات for a بنية, they must be مُضمن في an العنصر قائمة في the MSBuild ملف مشروع. Multiple ملفات can be تمت الإضافة إلى العنصر lists بواسطة either including the ملفات individually أو using أحرف البدل إلى تضمين many ملفات at once.
إلى declare عناصر individually
استخدم the Include السمات similar إلى following:
<CSFile Include="form1.cs"/>
ـــ أو ـــ
<VBFile Include="form1.vb"/>
ملاحظة
If عناصر في an العنصر collectio are not في the same الدليل كـ the ملف مشروع, you must specify the كامل أو نسبي مسار إلى the العنصر. فعلى سبيل المثال: Include="..\..\form2.cs".
إلى declare multiple عناصر
استخدم the Include السمات similar إلى following:
<CSFile Include="form1.cs;form2.cs"/>
ـــ أو ـــ
<VBFile Include="form1.vb;form2.vb"/>
Specifying Inputs مع أحرف البدل
You can also استخدم أحرف البدل إلى recursively تضمين الجميع ملفات أو فقط specific ملفات من subdirectories كـ inputs for a بنية. تظهر الأمثلة التالية تستند إلى مشروع الذي يحتوي تشغيل ملفات الرسومات في الدلائل التالية و الدلائل الفرعية، مع ملف المشروع الموجود في الدليل المشروع:
مشروع\صور\BestJpgs
مشروع\صور\ImgJpgs
مشروع\صور\ImgJpgs\Img1
إلى قم بتضمين الجميع ملفات.jpg في صور direcإلىry و subdirecإلىries
استخدم التالي Includeسمة:
Include="Images\\**\*.jpg"
إلى قم بتضمين الجميع ملفات.jpg يبدأ ب "img"
استخدم التالي Includeسمة:
Include="Images\**\img*.jpg"
لتضمين الجميع الملفات في الدلائل باستخدام أسماء ينتهي ب "jpgs"
استخدم واحد الإجراءات التالية Includeالسمات:
Include="Images\**\*jpgs\*.*"
ـــ أو ـــ
Include="Images\**\*jpgs\*"
تمرير عناصر إلى مهمة
في ملف مشروع، يمكنك استخدام @ منهج () في مهام إلى تحديد قائمة بالعناصر بكامل كالإدخال لبناء. يمكنك استخدم هذا المنهج ما إذا كان سرد الجميع الملفات حدة أو استخدم أحرف البدل.
إلى استخدام الجميع ملفات Visual C# أو Visual أساسى كإدخالات
استخدام Includeالسمات مشابهة إلى التالي:
<CSC Sources="@(CSFile)">...</CSC>
ـــ أو ـــ
<VBC Sources="@(VBFile)">...</VBC>
ملاحظة
يجب استخدام أحرف البدل مع عناصر إلى تحديد الإدخالات لبنية؛ لا يمكنك تحديد إدخالات استخدام Sourcesسمة في MSBuildtكـks مثل كـ Csc أو Vbc . المثال التالي هو غير صالح في ملف مشروع:
<CSC Sources="*.cs">...</CSC>
مثال
يلي تعليمات برمجية يظهر المثال مشروع يتضمن الجميع ملفات إدخال بشكل منفصل.
<Project DefaultTargets="Compile"
xmlns="https://schemas.microsoft.com/developer/msbuild/2003" >
<PropertyGroup>
<Builtdir>built</Builtdir>
</PropertyGroup>
<ItemGroup>
<CSFile Include="Form1.cs"/>
<CSFile Include="AssemblyInfo.cs"/>
<Reference Include="System.dll"/>
<Reference Include="System.Data.dll"/>
<Reference Include="System.Drawing.dll"/>
<Reference Include="System.Windows.Forms.dll"/>
<Reference Include="System.XML.dll"/>
</ItemGroup>
<Target Name="PreBuild">
<Exec Command="if not exist $(builtdir) md $(builtdir)"/>
</Target>
<Target Name="Compile" DependsOnTargets="PreBuild">
<Csc Sources="@(CSFile)"
References="@(Reference)"
OutputAssembly="$(builtdir)\$(MSBuildProjectName).exe"
TargetType="exe" />
</Target>
</Project>
يستخدم المثال التالي رمز حرف بدل إلى تضمين الجميع ملفات.cs.
<Project DefaultTargets="Compile"
xmlns="https://schemas.microsoft.com/developer/msbuild/2003" >
<PropertyGroup>
<builtdir>built</builtdir>
</PropertyGroup>
<ItemGroup>
<CSFile Include="*.cs"/>
<Reference Include="System.dll"/>
<Reference Include="System.Data.dll"/>
<Reference Include="System.Drawing.dll"/>
<Reference Include="System.Windows.Forms.dll"/>
<Reference Include="System.XML.dll"/>
</ItemGroup>
<Target Name="PreBuild">
<Exec Command="if not exist $(builtdir) md $(builtdir)"/>
</Target>
<Target Name="Compile" DependsOnTargets="PreBuild">
<Csc Sources="@(CSFile)"
References="@(Reference)"
OutputAssembly="$(builtdir)\$(MSBuildProjectName).exe"
TargetType="exe" />
</Target>
</Project>
راجع أيضًا:
المهام
كيفية القيام بما يلي: استبعاد ملفات من بنية