MSBuild command line - add dll reference

浪子不回头ぞ 提交于 2020-08-23 03:29:29

问题


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


回答1:


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



回答2:


You can't, msbuild only works on project files, which already contain all needed information.

If you want to kick off the compile yourself and have full control, use csc.exe directly, there you can use the /r:assembly switch.



来源:https://stackoverflow.com/questions/5066853/msbuild-command-line-add-dll-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!