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

转载自: http://blog.csdn.net/Hank_Huang/archive/2007/01/08/1477165.aspx

在VS2005 环境下面使用.NET Framework 1.1 进行编译由于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

 

 

related link:  http://blogs.msdn.com/jomo_fisher/archive/2005/04/22/410903.aspx

 

 

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值