2017-05-26 51 views
1

我們最近已遷移到Visual Studio 2017 Update 2。我們有一個.NET Core 1.1應用程序,它只針對.NET Framework 4.6.1,並且具有項目在同一解決方案中引用.NET Framework類庫。我們正在使用dotnet的1.0.4 SDK版本。使用.NET Core 1.1和新的VS 2017項目格式的dotnet發佈失敗

其中一個項目引用包含配置爲在構建上運行的T4模板。這需要導入Microsoft.TextTemplating.targets及相關程序集,以便可以通過MSBuild轉換T4模板。這些程序集反過來需要.NET Framework 4.6程序集(System,System.Data,System.Xml等)。

的Visual Studio 2017年沒有問題,構建代碼,然而,當我們試圖在我們的TeamCity建立使用dotnet builddotnet publish,該命令將失敗與以下輸出:根據研究,我

c:\xxx\Microsoft.TextTemplating.targets(340,5): error MSB4018: The "TransformTemplates" task failed unexpectedly. c:\xxx\Microsoft.TextTemplating.targets(340,5): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified. c:\xxx\Microsoft.TextTemplating.targets(340,5): error MSB4018: File name: 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

到目前爲止,運行T4轉換任務所需的.NET Framework引用沒有被dotnet CLI加載,但它們是由Visual Studio提供的,由於完全獨立的MSBuild工具鏈。

有什麼辦法可以使dotnet publish的工作方式與Visual Studio相同嗎?這個問題徹底打破了我們的CI/CD列車。我試圖將.NET標準作爲目標框架來檢查它是否可行,但我們使用了幾個不兼容的軟件包,因此這不是一個選項(例如Entity Framework 6.1)。

回答

3

基於dotnet的命令在MSBuild的.NET Core版本上運行,因此無法加載完整的框架程序集。如果這些程序集沒有.NET Core或.NET Standard版本,那麼在構建.NET Core版本的MSBuild期間加載它們是不可能的(這可能會轉移到.NET Core 2.0)。

爲了獲得CI/CD的工作,您需要使用VS版本的MSBuild。 dotnet publish只會轉發到msbuild,因此您可以獲得將參數傳遞給msbuild的相同行爲。例如:

dotnet publish -c Release 

成爲

msbuild /m /t:Publish /p:Configuration=Release 
相關問題