繁体   English   中英

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

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

我正在使用csc / csc2.exe手动编译应用程序。 我需要引用.NET 3.5 dll,但似乎编译器自动添加了.NET 4.0 dll(导致冲突)。

我手动引用了所需的mscorlib版本和其他系统dll。 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

我为每个引用的程序集收到以下错误:

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.

是什么导致编译器包含.NET 4.0 dll,我该怎么做才能阻止它包含它们?

更新:我不能使用MSBUILD,因为我已经有一个来自应用程序的响应文件(不是项目文件)。 该应用程序使用了过时的编译器版本,我正在尝试用支持C#6的新版本替换它们的编译器。 我已经使用Mono MCS编译器成功完成了这项任务,但无法与Roslyn一起工作。 我不能使用MCS编译器,因为它还不支持所有C#6功能。

使用MSBUILD的唯一方法是将响应文件解析回C#项目文件。 这对我来说似乎过度工程化了。

/noconfig选项添加到命令行,它应该按预期工作。

/ noconfig选项告诉编译器不要使用csc.rsp文件进行编译,该文件位于与csc.exe文件相同的目录中并从中加载。

csc.rsp文件引用.NET Framework附带的所有程序集。 Visual Studio .NET开发环境包含的实际引用取决于项目类型。

资源

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