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

查看:144
本文介绍了如何在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任务如下:

  <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?

此处,存在类似的问题,但是它对我没有多大帮助.

There's a similar question here but it doesn't help me much.

推荐答案

我已通过手动配置ToolPath使其指向sgen.exe的旧版本(版本2.0.50727.3038)来解决了此问题

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 SDKs \ Windows \ v7.0A \ Bin

On my machine, this is in: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin

我将ToolPath属性更改为:

I changed the ToolPath attribute to be:

ToolPath="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin"

这解决了问题.

默认情况下,它似乎在以下位置运行新的4.0框架版本:C:\ Program Files(x86)\ Microsoft SDKs \ Windows \ v7.0A \ Bin \ NETFX 4.0 Tools

It seems, by default, it's running the new 4.0 framework version in: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools

希望这对其他人有帮助.

Hope this helps somebody else.

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

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