我想建立一个常用函数的库。因此,我创建了一个 Microsoft Visual C# 2010 项目。这个项目包含几个*.cs
文件,每个文件都包含一个类。目前我的项目包含两个文件Common.cs
和Vars.cs
. 要从我的项目中构建 dll,我在命令行中运行以下命令。
C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc /target:library /reference:some.dll /out:Library.dll Library\Common.cs Library\Vars.cs
我的问题是,如果我添加其他*.cs
文件,我必须编辑这个构建命令。
如何创建构建脚本来自动执行此过程?
编辑:这是对我有用的解决方案:
我创建了一个名为build.xml
. 这是这个文件的内容。
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="CompileAll" ToolsVersion="3.5">
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- Import Project="c:\.net3.5\Microsoft.Csharp.targets" / -->
<PropertyGroup>
<!-- This AppName thing is the base name of your DLL or EXE -->
<AppName>MyLibraryName</AppName>
</PropertyGroup>
<!-- This build file compiles each .cs file into its own exe -->
<PropertyGroup Condition="'$(Configuration)'==''">
<Configuration>Debug</Configuration>
<!-- Default -->
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<Optimize>false</Optimize>
<DebugSymbols>true</DebugSymbols><!-- <OutputPath>.\bin</OutputPath> -->
<OutputPath>.\</OutputPath>
<OutDir>.\</OutDir>
<IntermediateOutputPath>.\</IntermediateOutputPath>
</PropertyGroup>
<!-- Specify the inputs by type and file name -->
<ItemGroup>
<CSFile Include="LibraryEtasHil\*.cs"/>
</ItemGroup>
<!-- specify reference assemblies for all builds in this project -->
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Runtime.Serialization" />
<!-- <Reference Include=".\ObjectDumper.dll" /> -->
<Reference Include="dummy.dll" />
</ItemGroup>
<Target Name="CompileAll" DependsOnTargets="ResolveAssemblyReferences">
<Message Text="Reference = @(Reference)" />
<Message Text="ReferencePath = @(ReferencePath)" />
<!-- Message Text="MS Build Tools path: $(MSBuildToolsPath)" / -->
<!-- Run the Visual C# compilation on all the .cs files. -->
<CSC
Sources="@(CSFile)"
References="@(ReferencePath)"
OutputAssembly="$(OutputPath)\$(AppName).dll"
EmitDebugInformation="$(DebugSymbols)"
TargetType="library"
Toolpath="$(MSBuildToolsPath)"
Nologo="true"
/>
</Target>
<!-- redefine the Clean target, from the Microsoft.csharp.targets file. (Last definition wins) -->
<Target Name="Clean">
<Delete Files="$(OutputPath)\$(AppName).dll"/>
<Delete Files="$(OutputPath)\$(AppName).pdb"/>
<Delete Files="%(CSFile.identity)~"/>
<Delete Files="build.xml~"/>
</Target>
要构建 dll,您只需在 Visual Studio 命令提示符下执行以下命令。
msbuild build.xml