8

我在这里查看了其他几个与 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?

4

4 回答 4

18

这似乎是我最近遇到的一个常见问题。

在“构建”选项卡上的项目属性中,将选项“生成序列化程序集”从“自动”设置为“关闭”。


更新

如果您尚未尝试过,请确保<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>已为 Release AND Debug 配置进行了设置。

于 2010-04-08T17:28:26.073 回答
0

我认为没有安装旧版本VS的痛苦的解决方案

请尝试以下方法:

键: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
于 2016-01-26T10:27:10.157 回答
0

在“构建”选项卡上的项目属性中,将“生成序列化程序集”选项从“自动”设置为“关闭”。

它解决了我的问题。

于 2017-06-22T06:37:43.560 回答
-2

我不知道发生了什么或为什么会发生这种情况,但我为解决这个问题所做的是安装 Visual Studio 2005。我已经安装了 .NET 2.0 SDK 和 .NET 3.5 SDK,但没有运气,但Visual Studio 2005 安装程序为我解决了这个问题。这是一个可怕的解决方案,但它仍然是一个解决方案。

希望我们能尽快迁移到 .NET 4.0 并彻底摆脱 .NET 2.0 及其问题。

于 2010-04-08T19:00:27.103 回答