gpt4 book ai didi

visual-studio-2010 - VS.NET 2010/MSBUILD 可以为 .NET 3.5 SP1 生成 XmlSerializers 吗?

转载 作者:行者123 更新时间:2023-12-04 01:01:18 26 4
gpt4 key购买 nike

我刚刚将包含 WinForms、通用库和 Web 应用程序的 VS 2008 解决方案升级到 VS 2010,但所有项目仍以 .NET 3.5 SP 1 为目标。我使用 this technique为我的通用库生成 XmlSerializers。 WinForms 应用程序运行良好。当我的 Web 应用程序尝试使用这些引用相同 XmlSerializers 的库运行时,它会抛出以下内容:

Server Error in '/WebSubscribers' Application. Could not load file or assembly 'Ceoimage.Basecamp.XmlSerializers' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'Ceoimage.Basecamp.XmlSerializers' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.



我已经使用 查看了 XmlSerializer 的引用。 .NET 反射器 并看到它同时引用了 mscorlib 的 2.0 和 4.0 版本以及 System.Data.Linq 的 3.5 和 4.0 版本.奇怪的是,它只使用了 System.Xml的4.0版本.那可能是我的问题。

如何使用这些 XmlSerializers 运行 Web 应用程序?当我简单地删除那些 XmlSerializer 时,Web 应用程序运行良好。这是一个选项,但如何强制 MSBUILD 为特定版本的 CLR 创建序列化程序?

这是我添加到强制创建 XmlSerializers 的项目文件中的 MSBuild 任务:
<Target Name="AfterBuild" DependsOnTargets="AssignTargetPaths;Compile;ResolveKeySource" Inputs="$(MSBuildAllProjects);@(IntermediateAssembly)" Outputs="$(OutputPath)$(_SGenDllName)">
<Delete Files="$(TargetDir)$(TargetName).XmlSerializers.dll" ContinueOnError="true" />
<SGen BuildAssemblyName="$(TargetFileName)" BuildAssemblyPath="$(OutputPath)" References="@(ReferencePath)" ShouldGenerateSerializer="true" UseProxyTypes="false" KeyContainer="$(KeyContainerName)" KeyFile="$(KeyOriginatorFile)" DelaySign="$(DelaySign)" ToolPath="$(SGenToolPath)">
<Output TaskParameter="SerializationAssembly" ItemName="SerializationAssembly" />
</SGen>
</Target>

最佳答案

MSBuild 4 将(应该……)使用 3.5 工具来构建 3.5 项目。但是,它看起来无法确定 3.5 工具在哪里并且正在使用 4.0 工具。结果是它正确构建了您的 3.5 项目(使用 CLR 2.0.50727 程序集),但 4.0 sgen.exe 工具正在生成 Ceoimage.Basecamp.XmlSerializers.dll 作为 CLR 4.0.30319 程序集。

MSBuild 使用注册表来获取 v3.5 工具的路径。如果无法识别到 3.5 工具的路径,则需要 v3.5 SDK 工具的 MSBuild 任务将回退到 v4.0 路径 - 查看用于设置 C:\Windows\Microsoft 中的 TargetFrameworkSDKToolsDirectory 属性的逻辑。 NET\Framework\v4.0.30319\Microsoft.NETFramework.props 如果你真的感兴趣。

您可以按如下方式诊断和修复可能的注册表问题:

安装进程监视器并设置过滤器以监视 msbuild 对注册表的访问(事件类:注册表,进程名称:msbuild.exe,所有类型的结果)

运行你的构建

搜索与“MSBuild\ToolsVersions\4.0\SDK35ToolsPath”匹配的 RegQueryValue 访问的进程监视器。请注意,这可能位于“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft”或“HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft”下

如果您查看注册表中的此项,您会看到它为另一个注册表值设置了别名,例如“$(注册表:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1\WinSDK-NetFx35Tools-x86@InstallationFolder)”
此后不久,您可能会看到“NAME NOT FOUND”结果,因为 msbuild 尝试从指定的键加载值。

应该清楚您需要从这里添加/修改哪些键。

注册表值错误的可能原因有几个。就我而言,Microsoft SDK v7.1 安装的问题意味着注册表项的名称不正确,这里已将其确定为错误:

http://connect.microsoft.com/VisualStudio/feedback/details/594338/tfs-2010-build-agent-and-windows-7-1-sdk-targeting-net-3-5-generates-wrong-embedded-resources

关于visual-studio-2010 - VS.NET 2010/MSBUILD 可以为 .NET 3.5 SP1 生成 XmlSerializers 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3549210/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com