簡體   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