SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Matt Ward

Targeting Different Frameworks with SharpDevelop

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="">
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <TargetFrameworkVersion>Mono v1.1</TargetFrameworkVersion>
  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
    <Compile Include="Main.cs" />
    <Compile Include="AssemblyInfo.cs" />
  <Import Project="$(SharpDevelopBinPath)\SharpDevelop.Build.CSharp.targets" />

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' " 
<Import Condition=" '$(TargetFrameworkVersion)' == 'Mono v2.0' "

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.
Published Oct 15 2005, 03:55 PM by MattWard
Filed under:



Mike Huguet said:

Want a free IDE for the .NET 2.0 release? You can get it, SharpDevelp 2.0.
November 5, 2005 10:25 PM

Matt Ward said:

SharpDevelop 2.1, revision 1157, allows VB.NET projects to target the older Microsoft Frameworks and...
February 18, 2006 6:29 PM
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this ( email address.