Daniel recently added support for .NET 1.1 and .NET 1.0 to SharpDevelop
2.0. Let us take a low level look at how SharpDevelop 2.0 targets
other frameworks. Targeting another framework involves a custom
.targets file and custom MSBuild tasks.
SharpDevelop Custom MSBuild Tasks and Targets
| Component |
Description |
| ICSharpCode.Build.Tasks.dll |
Assembly containing custom MSBuild tasks. |
| SharpDevelop.Build.Common.targets |
Specifies targets common to all SharpDevelop targets. |
| SharpDevelop.Build.CSharp.targets |
Specifies targets for C# projects that target a framework other than the default. |
| SharpDevelop.Build.Mono.Mcs.targets |
Defines the Mcs task. |
| SharpDevelop.Build.Mono.Gmcs.targets |
Defines the Gmcs task. |
| SharpDevelop.Build.MSIL.targets |
Specifies targets for ILAsm projects. |
What happens when another framework is targeted?
When the project has been configured to target a framework other than
the default, the project is modified to use a customised .targets file
and has a property added that specifies the framework being
targeted. Below is a project file for a console application that
targets Mono 1.1.
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>HelloMonoWorld</RootNamespace>
<AssemblyName>HelloMonoWorld</AssemblyName>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0534CD74-E5FA-4349-866E-4E0C6428E840}</ProjectGuid>
<TargetFrameworkVersion>Mono v1.1</TargetFrameworkVersion>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<Optimize>False</Optimize>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<Optimize>True</Optimize>
<DefineConstants>TRACE</DefineConstants>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
</PropertyGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(SharpDevelopBinPath)\SharpDevelop.Build.CSharp.targets" />
</Project>
The .csproj file has a <TargetFrameworkVersion>
element and includes a custom .targets file
"SharpDevelop.Build.CSharp.targets" instead of the usual
"Microsoft.CSharp.Targets".
The "SharpDevelop.Build.CSharp.targets" file looks at the
TargetFrameworkVersion information and targets the appropriate
runtime. If we are targeting Mono, the file imports one of the
Mono specific target files.
<Import Condition=" '$(TargetFrameworkVersion)' == 'Mono v1.1' "
Project="$(SharpDevelopBinPath)\SharpDevelop.Build.Mono.Mcs.targets"/>
<Import Condition=" '$(TargetFrameworkVersion)' == 'Mono v2.0' "
Project="$(SharpDevelopBinPath)\SharpDevelop.Build.Mono.Gmcs.targets"/>
These Mono specific files reference the custom MSBuild tasks in the ICSharpCode.Build.Tasks assembly.
If one of the Microsoft .NET frameworks is targeted, various
properties, such as CscToolPath, are changed so the correct compiler is
used, but no custom tasks are involved.