Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild command line - add dll reference

I use a makefile to compile my C# project. In this makefile, I create a library tools.dll calling csc.exe, OK.

Now, I want to use this .dll in my project. For some reasons, I have to use MSBuild.exe which use .csproj file. In .csproj file I added this section :

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

That's works fine !

But my question is : How can I add tools.dll reference from MSBuild command line ?

I need that, to call MSBuild.exe in makefile and give it the path of tools.dll file

like image 945
TheFrancisOne Avatar asked Feb 21 '11 13:02

TheFrancisOne


1 Answers

Actually you can.

<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>

to build your project with custom tools.dll use this command line:

msbuild.exe yourproject.csproj /p:Configuration=Release;Platform=AnyCPU /p:ToolsDllPath=C:\Gen\Tools\bin\Release\Tools.dll
like image 77
Sergio Rykov Avatar answered Sep 30 '22 07:09

Sergio Rykov