MSBuild命令行 - 添加dll引用

时间:2011-02-21 13:59:29

标签: c# dll msbuild reference

我使用makefile来编译我的C#项目。 在这个makefile中,我创建了一个库tools.dll,调用csc.exe,OK。

现在,我想在我的项目中使用这个.dll。 出于某些原因,我必须使用使用.csproj文件的MSBuild.exe。 在.csproj文件中,我添加了这一部分:

<Reference Include="TOOLS">
  <HintPath>C:\Gen\Lib\TOOLS.dll</HintPath>
</Reference>

这很好用!

但我的问题是: 如何从MSBuild命令行添加tools.dll引用?

我需要它,在makefile中调用MSBuild.exe并为其提供tools.dll文件的路径

2 个答案:

答案 0 :(得分:9)

其实你可以。

<Project InitialTargets="ValidateToolsDllExists" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="ValidateToolsDllExists">
    <Error
        Text=" The ToolsDllPath property must be set on the command line."
        Condition="'$(ToolsDllPath)' == ''" />
    <Error
        Text=" The ToolsDllPath property must be set to the full path to tools.dll."
        Condition="!Exists('$(ToolsDllPath)')" />
</Target>

<PropertyGroup>
     <!-- Default path to tools.dll -->
     <ToolsDllPath Condition="'$(ToolsDllPath)'==''">C:\Gen\Lib\TOOLS.dll</ToolsDllPath>
</PropertyGroup>
<ItemGroup>
     <Reference Include="Tools">
        <HintPath>$(ToolsDllPath)</HintPath>
     </Reference>
</ItemGroup>
</Project>

使用自定义 tools.dll 构建项目使用此命令行:

msbuild.exe yourproject.csproj /p:Configuration=Release;Platform=AnyCPU /p:ToolsDllPath=C:\Gen\Tools\bin\Release\Tools.dll

答案 1 :(得分:0)

你不能,msbuild只适用于已包含所有必需信息的项目文件。

如果您想自己开始编译并完全控制,请直接使用csc.exe,您可以使用/r:assembly开关。

相关问题