简体   繁体   English

使用Roslyn(csc.exe)定位.NET 3.5时手动编译C#

[英]Compiling C# manually while targetting .NET 3.5 with Roslyn(csc.exe)

I'm using csc/csc2.exe to manually compile an application. 我正在使用csc / csc2.exe手动编译应用程序。 I need to reference .NET 3.5 dlls, however it seems that the compiler automatically adds .NET 4.0 dlls as well (which is causing a conflict). 我需要引用.NET 3.5 dll,但似乎编译器自动添加了.NET 4.0 dll(导致冲突)。

I'm manually referencing the desired version of mscorlib, and other system dlls. 我手动引用了所需的mscorlib版本和其他系统dll。 Compilation from within Visual Studio succeeds, however compilation of the same response file manually from command prompt fails. Visual Studio中的编译成功,但是从命令提示符手动编译同一响应文件失败。

/nostdlib+
/platform:AnyCPU
/errorendlocation
/highentropyva-
/reference:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll"
/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll"
/reference:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll"
/debug+
/debug:full
/out:obj\Debug\Target.exe
/ruleset:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\\Rule Sets\MinimumRecommendedRules.ruleset"
/target:exe
/utf8output
Program.cs Properties\AssemblyInfo.cs

I'm getting the following errors for every referenced assembly: 我为每个引用的程序集收到以下错误:

error CS1703: Multiple assemblies with equivalent identity have been imported: 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.dll' and 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll'. Remove one of the duplicate references.

What causes the compiler to include .NET 4.0 dlls, and what can I do to prevent it from including them? 是什么导致编译器包含.NET 4.0 dll,我该怎么做才能阻止它包含它们?

UPDATE: I cannot use MSBUILD, because I already have a response file (not a project file) from an application. 更新:我不能使用MSBUILD,因为我已经有一个来自应用程序的响应文件(不是项目文件)。 The application used an outdated version of a compiler, and I'm trying to replace their compiler with a newer one that supports C#6. 该应用程序使用了过时的编译器版本,我正在尝试用支持C#6的新版本替换它们的编译器。 I've successfully done this task with Mono MCS compiler, but cannot get the same to work with Roslyn. 我已经使用Mono MCS编译器成功完成了这项任务,但无法与Roslyn一起工作。 I cannot use the MCS compiler, because it doesn't yet support all of C#6 features. 我不能使用MCS编译器,因为它还不支持所有C#6功能。

The only way to use MSBUILD would be to parse the response file back into a C# project file. 使用MSBUILD的唯一方法是将响应文件解析回C#项目文件。 This seems like over-engineering to me. 这对我来说似乎过度工程化了。

Add /noconfig option to command line and it should work as expected. /noconfig选项添加到命令行,它应该按预期工作。

The /noconfig option tells the compiler not to compile with the csc.rsp file, which is located in and loaded from the same directory as the csc.exe file. / noconfig选项告诉编译器不要使用csc.rsp文件进行编译,该文件位于与csc.exe文件相同的目录中并从中加载。

The csc.rsp file references all the assemblies shipped with the .NET Framework. csc.rsp文件引用.NET Framework附带的所有程序集。 The actual references that the Visual Studio .NET development environment includes depend on the project type. Visual Studio .NET开发环境包含的实际引用取决于项目类型。

Source 资源

Usual contents of csc.rps (v4.0.30319) : csc.rps常用内容(v4.0.30319):

/r:Accessibility.dll
/r:Microsoft.CSharp.dll
/r:System.Configuration.dll
/r:System.Configuration.Install.dll
/r:System.Core.dll
/r:System.Data.dll
/r:System.Data.DataSetExtensions.dll
/r:System.Data.Linq.dll
/r:System.Data.OracleClient.dll
/r:System.Deployment.dll
/r:System.Design.dll
/r:System.DirectoryServices.dll
/r:System.dll
/r:System.Drawing.Design.dll
/r:System.Drawing.dll
/r:System.EnterpriseServices.dll
/r:System.Management.dll
/r:System.Messaging.dll
/r:System.Runtime.Remoting.dll
/r:System.Runtime.Serialization.dll
/r:System.Runtime.Serialization.Formatters.Soap.dll
/r:System.Security.dll
/r:System.ServiceModel.dll
/r:System.ServiceModel.Web.dll
/r:System.ServiceProcess.dll
/r:System.Transactions.dll
/r:System.Web.dll
/r:System.Web.Extensions.Design.dll
/r:System.Web.Extensions.dll
/r:System.Web.Mobile.dll
/r:System.Web.RegularExpressions.dll
/r:System.Web.Services.dll
/r:System.Windows.Forms.Dll
/r:System.Workflow.Activities.dll
/r:System.Workflow.ComponentModel.dll
/r:System.Workflow.Runtime.dll
/r:System.Xml.dll
/r:System.Xml.Linq.dll

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM