MSBuild 在編譯解決方案時找不到 SGen
我在這裡查看了其他幾個與 SGen 相關的問題,要麼他們的答案不適用,要麼他們的答案沒有為我解決這個問題。我已經安裝了幾個 SDK 來解決這個問題,但沒有運氣。不應更改引用類型,因為這是唯一存在問題的地方。曾經的建議是將 SGen.exe 放入
C:\Windows\Microsoft.NET\Framework\v3.5文件夾中,但在沒有問題的盒子上沒有這樣做。在這種情況下,SGen.exe它確實存在並且就在它應該在的地方,但是 MSBuild 仍然因為某種原因無法找到它!背景:
我們有一個自動化建構的 NAnt 腳本。在這種情況下,NAnt 正在呼叫 MSBuild,而 MSBuild 正在生成聲稱無法找到 SGen 的錯誤。該項目基於 .NET 3.5。我有我的主要開發環境(64 位 Vista Ultimate),其中腳本執行良好,我試圖在 VM 中複製它(64 位 Win 7 Ultimate)。我認為我擁有一切都應該可以使用的東西,但這在 Win7 機器上失敗了(在 Vista 機器上完美執行)。
我在這兩個盒子之間做了一些比較,它們在這方面看起來都一樣,但仍然失敗。例如,兩台機器上的
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework’sdkInstallRootv2.0值都設置為。C:\Program Files\Microsoft.NET\SDK\v2.0 64bit\在兩台機器上,SGen.exe都在該路徑的bin子目錄中。NAnt 腳本:
<target name="report-installer" depends="fail-if-environment-not-set"> <exec program="MSBuild.exe" basedir="${framework35.directory}"> <arg value="${tools.directory.current}\ReportInstaller\ReportInstaller.sln" /> <arg value="/p:Configuration=${buildconfiguration.current}" /> </exec> </target>我得到的錯誤資訊是這樣的:
report-installer: [exec] Microsoft (R) Build Engine Version 3.5.30729.4926 [exec] [Microsoft .NET Framework, Version 2.0.50727.4927] [exec] Copyright (C) Microsoft Corporation 2007. All rights reserved. [exec] [exec] Build started 4/8/2010 11:28:23 AM. [exec] Project "C:\Projects\Production\Tools\ReportInstaller\ReportInstaller.sln" on node 0 (default targets). [exec] Building solution configuration "Release|Any CPU". [exec] Project "C:\Projects\Production\Tools\ReportInstaller\ReportInstaller.sln" (1) is building "C:\Projects\Production\Tools\ReportInstaller\ReportInstaller.csproj" (2) on node 0 (default targets). [exec] Could not locate the .NET Framework SDK. The task is looking for the path to the .NET Framework SDK at the location specified in the SDKInstallRootv2.0 value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework. You may be able to solve the problem by doing one of the following: 1.) Install the .NET Framework SDK. 2.) Manually set the above registry key to the correct location. [exec] CoreCompile: [exec] Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files. [exec] C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1902,9): error MSB3091: Task failed because "sgen.exe" was not found, or the .NET Framework SDK v2.0 is not installed. The task is looking for "sgen.exe" in the "bin" subdirectory beneath the location specified in the SDKInstallRootv2.0 value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework. You may be able to solve the problem by doing one of the following: 1.) Install the .NET Framework SDK v2.0. 2.) Manually set the above registry key to the correct location. 3.) Pass the correct location into the "ToolPath" parameter of the task. [exec] Done Building Project "C:\Projects\Production\Tools\ReportInstaller\ReportInstaller.csproj" (default targets) -- FAILED. [exec] Done Building Project "C:\Projects\Production\Tools\ReportInstaller\ReportInstaller.sln" (default targets) -- FAILED. [exec] [exec] Build FAILED. [exec] [exec] "C:\Projects\Production\Tools\ReportInstaller\ReportInstaller.sln" (default target) (1) -> [exec] "C:\Projects\Production\Tools\ReportInstaller\ReportInstaller.csproj" (default target) (2) -> [exec] (GenerateSerializationAssemblies target) -> [exec] C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1902,9): error MSB3091: Task failed because "sgen.exe" was not found, or the .NET Framework SDK v2.0 is not installed. The task is looking for "sgen.exe" in the "bin" subdirectory beneath the location specified in the SDKInstallRootv2.0 value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework. You may be able to solve the problem by doing one of the following: 1.) Install the .NET Framework SDK v2.0. 2.) Manually set the above registry key to the correct location. 3.) Pass the correct location into the "ToolPath" parameter of the task. [exec] [exec] 0 Warning(s) [exec] 1 Error(s) [exec] [exec] Time Elapsed 00:00:00.24 [call] C:\Projects\Production\Source\reports.build(15,4): [call] External Program Failed: C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe (return code was 1)我在這裡做錯了什麼導致MSBuild仍然無法找到SGen?
這似乎是我最近遇到的一個常見問題。
在“建構”選項卡上的項目屬性中,將選項“生成序列化程序集”從“自動”設置為“關閉”。
更新
如果您尚未嘗試過,請確保
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>已為 Release AND Debug 配置進行了設置。
我認為沒有安裝舊版本VS的痛苦的解決方案
請嘗試以下方法:
- 下載 + 安裝 .NET Framework 2.0 軟體開發工具包 (SDK) (x86): https ://www.microsoft.com/en-us/download/details.aspx?id=19988
- 確保存在以下 RegKey:
鍵:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework\v2.0\
字元串值:名稱:InstallationFolder 值(預設):C:\Program Files (x86)\Microsoft.NET\SDK\v2.0\
或將此程式碼保存為 .reg 文件並執行:
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2.0] "InstallationFolder"="C:\\Program Files (x86)\\Microsoft.NET\\SDK\\v2.0