我正在尝试创建一个简单的命令行工具,该工具应该在编译项目之前执行。目标是做一些前期工作,然后通过调用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>
。但是没有我的工具,项目正在编译。我在这里做错了什么?