我在这里查看了其他几个与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?
最佳答案
这些天我自己遇到了一个常见问题。
在“构建”选项卡上的项目属性中,将选项“生成序列化程序集”从“自动”设置为“禁用”。
更新
如果尚未尝试过,请确保已为Release AND Debug配置设置了<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
。
关于.net - 编译解决方案时,MSBuild无法找到SGen,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2601911/