在VS2005 环境下面使用.NET Framework 1.1 进行编译

来源:互联网 发布:足球阵容软件 编辑:程序博客网 时间:2024/05/14 19:58

由于MSBuild 未能直接提供编译.NET framework 1.1的功能, 不能直接在VS2005下使用.NET framework 1.1 编译

幸运的是  MSBuild有强大的扩展性,可以使我们去找到一种办法去解决这个问题。

让我们来看看应该怎么做:

 首先把下面这个XML 保存为C:/program files/msbuild/CrossCompile.CSharp.targets, 一定要是这个路径

<!--
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Written by Jomo Fisher
-->
<Project
 DefaultTargets="Build"
 xmlns="
http://schemas.microsoft.com/developer/msbuild/2003">
  <!--
 These two property groups inform VS that there is a Platform called .NET 1.1.
 -->
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|.NET 1.1' ">
    <DebugSymbols Condition="'$(DebugSymbols)'==''">true</DebugSymbols>
    <DebugType Condition="'$(DebugType)'==''">full</DebugType>
    <Optimize Condition="'$(Optimize)'==''">false</Optimize>
    <OutputPath Condition="'$(OutputPath)'==''">bin/.NET 1.1/Debug/</OutputPath>
    <DefineConstants Condition="'$(DefineConstants)'==''">DEBUG;TRACE</DefineConstants>
    <DefineConstants>$(DefineConstants);TARGETTING_FX_1_1</DefineConstants>
    <ErrorReport></ErrorReport>
    <WarningLevel Condition="'$(WarningLevel)'==''">4</WarningLevel>
    <UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>
    <CscToolPath>$(SystemRoot)/Microsoft.NET/Framework/v1.1.4322</CscToolPath>
    <TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|.NET 1.1' ">
    <DebugType Condition="'$(DebugType)'==''">pdbonly</DebugType>
    <Optimize Condition="'$(Optimize)'==''">true</Optimize>
    <OutputPath Condition="'$(OutputPath)'==''">bin/.NET 1.1/Release/</OutputPath>
    <DefineConstants Condition="'$(DefineConstants)'==''">TRACE</DefineConstants>
    <DefineConstants>$(DefineConstants);TARGETTING_FX_1_1</DefineConstants>
    <ErrorReport></ErrorReport>
    <WarningLevel Condition="'$(WarningLevel)'==''">4</WarningLevel>
    <UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>
    <CscToolPath>$(SystemRoot)/Microsoft.NET/Framework/v1.1.4322</CscToolPath>
    <TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
  </PropertyGroup>
  <!--
 Import the standard C# targets
 -->
  <Import Project="$(MSBuildBinPath)/Microsoft.CSharp.targets" />
  <!--
 Now that the standard targets have been brought in. Override some properties
 and items it created.
 -->
  <PropertyGroup>
    <AvailablePlatforms>$(AvailablePlatforms),.NET 1.1</AvailablePlatforms>
    <AssemblySearchPaths Condition=" '$(Platform)' == '.NET 1.1' ">
      {CandidateAssemblyFiles};
      $(ReferencePath);
      {HintPathFromItem};
      {TargetFrameworkDirectory};
      {AssemblyFolders};
      $(OutputPath);
      {GAC}
    </AssemblySearchPaths>
    <TargetFrameworkDirectory Condition=" '$(Platform)' == '.NET 1.1'">
      $(SystemRoot)/Microsoft.NET/Framework/v1.1.4322
    </TargetFrameworkDirectory>
  </PropertyGroup>
  <ItemGroup Condition=" '$(Platform)' == '.NET 1.1'">
    <TargetFrameworkDirectoryItem Include="$(SystemRoot)/Microsoft.NET/Framework/v1.1.4322">
      <InProject>false</InProject>
    </TargetFrameworkDirectoryItem>
  </ItemGroup>
  <!--
 Override this target from Microsoft.Common.Targets so that we can supply our own
 value for $(TargetFrameworkDirectory). This controls where assembly resolution
 logic finds FX assemblies.
 -->
  <Target
         Name="GetFrameworkPaths"
         DependsOnTargets="$(GetFrameworkPathsDependsOn)">
    <!-- Get the path to the target .NET framework directory. -->
    <GetFrameworkPath
     Condition=" '$(Platform)' != '.NET 1.1' ">
      <Output TaskParameter="Path" PropertyName="TargetFrameworkDirectory"/>
      <Output TaskParameter="Path" ItemName="TargetFrameworkDirectoryItem"/>
    </GetFrameworkPath>
    <!-- Get the path to the target .NET framework SDK directory. -->
    <GetFrameworkSDKPath
     Condition=" '$(Platform)' != '.NET 1.1' ">
      <Output TaskParameter="Path" PropertyName="TargetFrameworkSDKDirectory"/>
      <Output TaskParameter="Path" ItemName="TargetFrameworkSDKDirectoryItem"/>
    </GetFrameworkSDKPath>
  </Target>
  <!--
 For 1.1 builds, intercept the call to CorResGen target (which generates 2.0 resources) and
 slip in a call to our own CoreResGen_1_1.
 
 Handily, the devices version of the ResGen task is able to call the 1.1 version of
 ResGen directly.
 -->
  <UsingTask TaskName="CFResGen" AssemblyFile="$(MSBuildBinPath)/Microsoft.CompactFramework.Build.Tasks.dll" />
  <PropertyGroup Condition="'$(Platform)' == '.NET 1.1'">
    <ResGenDependsOn>ResolveAssemblyReferences;BeforeResGen;CoreResGen_1_1;AfterResGen</ResGenDependsOn>
  </PropertyGroup>
  <Target
         Name="CoreResGen_1_1"
         DependsOnTargets="$(CoreResGenDependsOn)">
    <CFResGen
              Condition = "
'@(ResxWithNoCulture)' != ''"
              Sources = "@(ResxWithNoCulture)"
              UseSourcePath = "$(UseSourcePath)"
              StateFile = "$(IntermediateOutputPath)$(MSBuildProjectFile).CrossCompileResGen.Cache"
              OutputResources = "@(ManifestResourceWithNoCultureName->'$(IntermediateOutputPath)%(Identity).resources')"
        >
      <!-- Appending to 'FilesWritten' list lets us be part of Clean and Incremental Clean. -->
      <Output TaskParameter = "FilesWritten" ItemName="FileWrites"/>
      <Output TaskParameter = "OutputResources" ItemName="ManifestResourceWithNoCulture"/>
    </CFResGen>
    <CFResGen
              Condition = "
'@(ResxWithCulture)' != ''"
              Sources = "@(ResxWithCulture)"
              UseSourcePath = "$(UseSourcePath)"
              StateFile = "$(IntermediateOutputPath)$(MSBuildProjectFile).CrossCompileResGen.Cache"
              OutputResources = "@(ManifestResourceWithCultureName->'$(IntermediateOutputPath)%(Identity).resources')"
        >
      <!-- Appending to 'FilesWritten' list lets us be part of Clean and Incremental Clean. -->
      <Output TaskParameter = "FilesWritten" ItemName="FileWrites"/>
      <Output TaskParameter = "OutputResources" ItemName="ManifestResourceWithCulture"/>
    </CFResGen>
  </Target>
</Project>

然后新建一个2005的c#项目 或者转换一个2003的项目到2005的项目格式. 取名为: myApp

手工编辑myApp.csproj

<Import Project="$(MSBuildExtensionsPath)/CrossCompile.CSharp.targets" />

 

 

 

 

替换 整个<Import >节点

 

保存

重新加载项目

在配置管理器(Configuration Manager)里面

平台(platform)下拉菜单里面 选择.NET 1.1 ()

OK. 如果代码没有问题就可以编译了

Enjoy 

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 报的培训班跑路怎么办 巡视组举报后会怎么办 巡视组交办不办怎么办 分手以后还要不要联系忘不了怎么办 父母穷且不上进怎么办 惹父母生气了该怎么办 小孩戒奶不吃奶粉怎么办 孩子听不进去话怎么办 异性好朋友喜欢自己亲吻自己怎么办 对方对你反感了怎么办 家长偷看孩子日记老师怎么办 儿子与父母相冲怎么办 初二孩子不争气老师打他怎么办? 孩子被老师打又怎么办 家里2个孩子打架怎么办 一年级的学生特别会顶嘴怎么办 私立学校的学生顶嘴老师该怎么办 孩子做错事家长不道歉怎么办 孩孑语文成绩差怎么办 高三了孩子不愿意补课怎么办 四年级的孩子上课喜欢讲小话怎么办 五年级孩子太叛逆怎么办 二年级话唠孩子怎么办 家有老人带孩子怎么办 不会看孩子。孩子一哭就害怕怎么办 孩子不老实爱动怎么办 4周孩子脾气大怎么办 老公脾气暴躁爱骂人怎么办? 当妈妈了脾气不好怎么办 父亲很坏不顾家很会赌钱怎么办 妈妈骂我很难听怎么办 父母管的太严怎么办 2岁宝宝哭闹不止怎么办 8岁儿童叛逆期怎么办 两岁宝宝叛逆期怎么办 4个月小孩哭怎么办 2个月孩子爱哭怎么办 小孩挑衅大人被大人打怎么办 在学校犯了错怎么办 孩子在学校爱捣乱怎么办 小孩老是在学校捣乱怎么办