.net Visual Studio正在更改我的目标运行时?
我的一位同事对他的开发环境(Win 7+VS 2010)有点问题: 我们有一个引用.net 2.0的类库项目,如果我们使用“调试”构建它,并使用Reflector打开它,我们可以看到“目标运行时:2.0…”如果我们使用“发布”配置构建它,我们可以看到“目标运行时:v4.0”(如果我们在测试服务器中使用它,我们会收到类似“此程序集是由比以前更新的运行时构建的”这样的错误消息) 在项目属性中,我可以看到“.NETFramework 2.0”。在我的.csproj中,我有.net Visual Studio正在更改我的目标运行时?,.net,visual-studio,msbuild,.net,Visual Studio,Msbuild,我的一位同事对他的开发环境(Win 7+VS 2010)有点问题: 我们有一个引用.net 2.0的类库项目,如果我们使用“调试”构建它,并使用Reflector打开它,我们可以看到“目标运行时:2.0…”如果我们使用“发布”配置构建它,我们可以看到“目标运行时:v4.0”(如果我们在测试服务器中使用它,我们会收到类似“此程序集是由比以前更新的运行时构建的”这样的错误消息) 在项目属性中,我可以看到“.NETFramework 2.0”。在我的.csproj中,我有 <TargetFram
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
v2.0
你知道吗
编辑
这是我的.csproj的开始
<Project ToolsVersion="2.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E7122A64-C206-47EB-A511-763FF9C9D560}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ControlSkin3</RootNamespace>
<AssemblyName>ControlSkin3</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Nonshipping>true</Nonshipping>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<CodeAnalysisCulture>en-en</CodeAnalysisCulture>
<TargetCulture>en-en</TargetCulture>
<SccProvider>SAK</SccProvider>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
调试
任意CPU
9.0.30729
2
{E7122A64-C206-47EB-A511-763FF9C9D560}
图书馆
性质
控制皮肤3
控制皮肤3
v2.0
512
真的
萨克
萨克
萨克
恩恩
恩恩
萨克
真的
满的
假的
bin\Debug\
调试;痕迹
促使
4.
关
pdbonly
真的
bin\Release\
痕迹
v2.0
促使
4.
关
我遇到了同样的问题,VS10中的3.5目标类库在Reflector中的目标运行时为v4.0,并且在将唯一supportedRuntime设置为v2.0的应用程序中使用时导致了问题
在我的例子中,它必须与一个生成后事件有关,该事件会对程序集进行反汇编,执行一些魔术,然后像这样再次“汇编”它:
call "$(DevEnvDir)..\Tools\vsvars32.bat"
ildasm "$(TargetFileName)" /out=myassembly.il /nobar /linenum
magic.exe myassembly.il ilasm myassembly.changed.il
ilasm myassembly.changed.il /DLL /OUTPUT="$(TargetFileName)"
这在VS2008中运行良好,因为path环境变量指向框架的v2.0版本。在VS2010中,它们似乎指向v4.0版本,因此在处理IL时,它会创建4.0代码
ilasm.exe没有一个开关来告诉它为v2.0版本构建,但存在于每个框架版本的特定版本中。为了解决这个问题,我指定了工具的完整路径:
call "$(DevEnvDir)..\Tools\vsvars32.bat"
"%WindowsSdkDir%bin\ildasm "$(TargetFileName)" /out=myassembly.il /nobar /linenum
magic.exe myassembly.il ilasm myassembly.changed.il
%FrameworkDir%\v2.0.50727\ilasm myassembly.changed.il /DLL /OUTPUT="$(TargetFileName)"
直到你的评论,我才知道它是什么,所以不,我不使用它。你能发布你的csproj的开头吗,直到项目组定义引用?这很奇怪。您的发布属性中有一个额外的TargetFrameworkVersion,但它与您当前的问题无关(我在我的一个项目中尝试过,它并不麻烦)。如何启动调试和发布版本?来自VS?从命令行?是否有生成前或生成后事件?没有生成前/生成后事件。要启动构建,我在VS:build->configurationmanager->列表中选择Debug或Release。我将尝试查看详细的输出,可能有一些内容。感谢您的帮助,但我没有使用任何生成后事件,但可能我不理解您的回答请注意,使用
%FrameworkDir%\v2.0.50727\ilasm
也可以在visual studio 2010命令提示符中工作,而不仅仅是在生成事件中