【问题标题】:Batch "input line is too long" while calling csc.exe from bat script从 bat 脚本调用 csc.exe 时批处理“输入行太长”
【发布时间】:2019-11-14 14:50:50
【问题描述】:

我的代码试图让 csc.exe 引用 /DLLs 目录中的所有 .dll 文件。

@echo on
setlocal enableextensions enabledelayedexpansion
del Assembly.dll
cd DLLs
set "imports="
for /r %%i in ("*.dll") do set "imports=!imports!,%%i"
set "imports=%imports:~1%"
cd ..
csc.exe -nostdlib -target:library -out:Assembly.dll Loader.cs MainScript.cs -r:%imports%

但是,如果目录中的 .dll 太多,由于 cmd.exe 无法处理那么多字符,最后一行会给我一个“输入行太长”错误。您对此问题有任何解决方法/解决方案吗?

【问题讨论】:

  • 请尝试命令csc.exe /? 看看@<file> 是否可行。 docs.microsoft.com/en-us/dotnet/csharp/language-reference/…
  • 我没有看到 -rcsc 参数
  • 您的for in do 可以简化为:for /r %%i in ("*.dll") do set "imports=imports,%%i",除非您只是简单地写错了。如果减少它,则不需要延迟扩展。使用此代码或您的代码,我得到了相同的结果。
  • @somebadhat: set "imports=imports,%%i"set "imports=!imports!,%%i" 是一个巨大的区别。
  • @somebadhat -r-reference 的简写形式。

标签: windows batch-file dll cmd csc


【解决方案1】:

comment 中所述,您应该使用链接到.rsp 文件的@ compiler option 文件,您可以在其中存储编译器选项(包括引用)。

该文件看起来像 csc.rsp(与 csc.exe 在同一文件夹中),除非指定了 -noconfig compiler option,否则它是每个编译的一部分。

例如references.rsp:

-r:Microsoft.CSharp.dll
-r:System.Core.dll
-r:System.dll
-r:System.Windows.Forms.Dll

您可以在批处理文件中以编程方式创建文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-10
    • 2019-09-19
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多