gpt4 book ai didi

c# - MSBuild 命令行 - 添加 dll 引用

转载 作者:太空狗 更新时间:2023-10-29 22:28:35 25 4
gpt4 key购买 nike

我使用 makefile 来编译我的 C# 项目。在此 makefile 中,我创建了一个调用 csc.exe 的库 tools.dll,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 文件的路径

最佳答案

其实你可以。

<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

关于c# - MSBuild 命令行 - 添加 dll 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5066853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com