手动执行csc.exe时编译器因cs2007错误而失败

时间:2018-03-09 16:31:08

标签: c# visual-studio csc

首先我要做的是:

我正在尝试创建一个简单的命令行工具,该工具应该在编译项目之前执行。目标是做一些前期工作,然后通过调用csc.exe执行真正的编译。

到目前为止我得到了什么:

我创建了一个保存传递参数的最小项目。我不得不保存rsp文件的内容,因为这个临时文件在进程后被销毁了。

代码

static void Main(string[] args)
{
  // Path to temporary rsp file
  var rsp = args[1].Replace("@", "");
  // All lines from the rsp-file
  var files = File.ReadAllLines(rsp);

  // For testing purposes saving the args and the content of the rsp file
  File.WriteAllText("passedArgs.txt", String.Join(" ", args));
  File.WriteAllText("text.rsp", String.Join(" ", files));
}

修改了csproj文件

<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <!-- deleted unimportant stuff -->
    <!-- compiler.exe is the compiled tool from the code above -->
    <CscToolPath>$(SolutionDir)</CscToolPath>
    <CscToolExe>compiler.exe</CscToolExe>
</PropertyGroup>

提取数据

Args:/noconfig @C:\Users\xx\Source\Repos\xxTest\xxTest\text.rsp
Rsp文件:/nowarn:1701,1702,2008 /nostdlib+ ... classes etc

上一个测试步骤(麻烦来了) 我已打开控制台并执行:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319> .\csc.exe /noconfig @C:\Users\xx\Source\Repos\xxTest\xxTest\text.rsp

错误

fatal error CS2007: Unbekannte Option: '/ruleset:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Team        Tools\Static Analysis Tools\\Rule Sets\MinimumRecommendedRules.ruleset"'
PS C:\Windows\Microsoft.NET\Framework64\v4.0.30319>

它说unknown option <ruleset>。但是没有我的工具,项目正在编译。我在这里做错了什么?

到目前为止谷歌没有帮助。 非常感谢你

0 个答案:

没有答案