如何在 Msbuild 中将 SGEN 工具路径设置为目标 3.5 框架 [英] How to set SGEN toolpath in Msbuild to target 3.5 framework

查看:20
本文介绍了如何在 Msbuild 中将 SGEN 工具路径设置为目标 3.5 框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将一个项目从 VS2008 升级到 VS2010,但我仍然以 3.5 框架为目标.

I've just upgraded a project from VS2008 to VS2010 but I'm still targeting the 3.5 framework.

在我的项目文件中,我有一个自定义任务来运行 SGEN 以生成我的 XmlSerializers.dll.但是,正在运行的 sgen 版本针对 4.0 框架.结果,当我运行我的应用程序时,我收到错误消息:

In my project file I have a custom task to run SGEN to generate my XmlSerializers.dll. However the version of sgen being run targets the 4.0 framework. As a result, when I run my application I get the error message:

无法加载文件或程序集‘XXXX.XXXX.XmlSerializers’或其依赖项之一.此程序集是由比当前加载的运行时更新的运行时构建的,无法加载."

"Could not load file or assembly 'XXXX.XXXX.XmlSerializers' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."

Sgen 任务如下所示:

The Sgen task looks like this:

  <Target Name="AfterBuild" DependsOnTargets="AssignTargetPaths;Compile;ResolveKeySource" Inputs="$(MSBuildAllProjects);@(IntermediateAssembly)" Outputs="$(OutputPath)$(_SGenDllName)">
    <!-- Delete the file because I can't figure out how to force the SGen task. -->
    <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>

还有 ToolPath="$(SGenToolPath)".如何让它运行面向 3.5 的版本?

There's the ToolPath="$(SGenToolPath)". How do I make it run the version that targets 3.5?

这里有一个类似的问题对我帮助不大.

推荐答案

我通过手动配置 ToolPath 以指向旧版(版本 2.0.50727.3038)sgen.exe 解决了这个问题

I have solved this by manually configuring the ToolPath to point to the old (version 2.0.50727.3038) version of sgen.exe

在我的机器上,它位于:C:Program Files (x86)Microsoft SDKsWindowsv7.0ABin

On my machine, this is in: C:Program Files (x86)Microsoft SDKsWindowsv7.0ABin

我将 ToolPath 属性更改为:

I changed the ToolPath attribute to be:

ToolPath="C:Program Files (x86)Microsoft SDKsWindowsv7.0ABin"

这解决了问题.

它似乎在默认情况下运行新的 4.0 框架版本:C:Program Files (x86)Microsoft SDKsWindowsv7.0ABinNETFX 4.0 Tools

It seems, by default, it's running the new 4.0 framework version in: C:Program Files (x86)Microsoft SDKsWindowsv7.0ABinNETFX 4.0 Tools

希望这对其他人有帮助.

Hope this helps somebody else.

这篇关于如何在 Msbuild 中将 SGEN 工具路径设置为目标 3.5 框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆