Re: MSBuild file for .Net 1.0, 1.1, 2.0, Compact Framework 1.0 & 2.0 and Mono

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



The url doesn't seems to work.

Gustavo Guerra wrote:
Forget ContinueOnErrorWhenBuildingForAllPlatforms, wasn't working after all.
Latest version at https://ovatsus.ath.cx/Ovatsus.CSharp.targets

"Gustavo Guerra" <gmcg@xxxxxxx> wrote in message news:eLkrZl$0FHA.3756@xxxxxxxxxxxxxxxxxxxxxxx

Greetings,

Intro:

I'm currently working in a library that has to target both .Net 2.0 and .Net
Compact Framework 2.0.
My initial approach was to have two projects for each assembly. The source
code would be all the same, with #if's testing for the compact or the full
framework. One of the projects would have all the files, and the other all
the files from the first linked.
As the number of source files and assemblies growed, this turned into
problematic.
At some time, I also wanted to test if my code worked in mono, even if it
wasn't required.
So I thought of using msbuild to customize my build. I started googling, and
found msbuild files from Jomo Fisher and Robert McLaws that would target
previous versions of .Net. And I also found msbuild files from Mike Hull and
Andy Waddell that would target Mono. But nothing to target Compact Framework
So, a week's work of researching the docs, posting on miscrosoft msbuild
forum and other newsgroups, and I've come up with a msbuild file that does
all that I wanted.


I'm sharing it here so everyone can use it and also to get improvements for
it.
The file is called Ovatsus.CSharp.targets and is attached in this message


Usage Instructions:

-Copy the Ovatsus.CSharp.targets to C:\Program Files\MSBuild
-Replace the <Import> element from your project file with <Import
Project="$(MSBuildExtensionsPath)\Ovatsus.CSharp.targets"/>

After that you have 11 new Platforms:
.NET 1.0
.NET 1.1
.NET 2.0
.NET CF 1.0 (Pocket PC 2003)
.NET CF 1.0 (Smartphone 2003)
.NET CF 2.0 (Pocket PC 2003)
.NET CF 2.0 (Windows CE 5.0)
.NET 1.1 (Mono Compiler & Libraries)
.NET 2.0 (Mono Compiler & Libraries)
.NET 1.1 (Mono Libraries)
.NET 2.0 (Mono Libraries)

The existing Any CPU platform remains, and if you build with that platform
selected you will build for all targets sequentially. It continues to be the
default platform so if you just invoke msbuild.exe from the project
directory, you'll build everything.


The difference between the "Mono Libraries" platforms and "Mono Compiler &
Libraries" platforms is that in the first, the compiler is still csc and not
the mono mcs or gmcs. These targets exists so you can debug inside VS.


There are also defined some conditional compilation symbols. They are,
respectively for the above platforms:
NET_1_0
NET_1_1
NET_2_0
NET_CF;NET_CF_1_0;PocketPC
NET_CF;NET_CF_1_0;Smartphone
NET_CF;NET_CF_2_0;PocketPC
NET_CF;NET_CF_2_0;WindowsCE
NET_1_1;Mono
NET_2_0;Mono
NET_1_1;Mono
NET_2_0;Mono

All works fine from msbuild.exe. From withing VS there are a few things
worth notice:
1-You can't deploy to the compact framework, and you can design cf forms
visually, but VS won't know your form is for the CF, and will probably set
properties that don't exist in CF. You can always create a specific CF
project, that just uses all code, including forms, from the multi-platform
project
2-If you have project references, VS will only find the referenced project
assemblies if you set both projects to the same Platform, and that platform
can't be AnyCPU. What you can do is build for all platforms in the
referenced project, unload it and then build for any platform you like
(including all at once - AnyCPU) in the referencee project. In this case VS
will work correctly. Note that from msbuild.exe it all works correctly.


Also, you can override the platform names before including
Ovatsus.CSharp.targets by overriding the following properties:
NET_1_0
NET_1_1
NET_2_0
NET_CF_1_0_PocketPC
NET_CF_1_0_Smartphone
NET_CF_2_0_PocketPC
NET_CF_2_0_WinCE
Mono_1_1_Full
Mono_2_0_Full
Mono_1_1_LibOnly
Mono_2_0_LibOnly

You can also change the conditional compilation symbols, by overriding these
properties:
NET_1_0_Constant
NET_1_1_Constant
NET_2_0_Constant
NET_CF_1_0_Constant
NET_CF_2_0_Constant
NET_CF_Constant
Mono_Constant


I don't suport overriding the symbols PocketPC, Smartphone or WindowCE,
because these names already existed in VS when building for CF.

You can also override these two properties:
BinDir
ObjDir

By default, they are setted to bin and obj, respectively. You can override
them to something else, if you want. This is usefull if you have the source
code in cvs or svn, for example, and don't want to have to mess with
settings the ignore directories. In that case, you can set those properties
to ..\..\bin and ..\..\obj, for example, so it's out of your working copy.
When building inside VS, it will stubbornly create the obj directories below
your project directory, but as it only contains more empty subdirectories,
that's less of a problem.


You can also override the property MonoPath, that's hardcoded to C:\Program
Files\Mono-1.1.9.2, or set an environment variable with that name. Please
don't surround it with ".


At last, you can also override the property
ContinueOnErrorWhenBuildingForAllPlatforms, that defaults to false.

Best regards,
Gustavo Guerra









.



Relevant Pages

  • Re: MSBuild file for .Net 1.0, 1.1, 2.0, Compact Framework 1.0 & 2.0 and Mono
    ... > found msbuild files from Jomo Fisher and Robert McLaws that would target ... > The existing Any CPU platform remains, and if you build with that platform ... > 1-You can't deploy to the compact framework, and you can design cf forms ... you can override the platform names before including ...
    (microsoft.public.vstudio.development)
  • Re: Information on migration of DMS2200 to relational databases
    ... application infrastructure is available on the possible target ... DML for DMS 2200 access and currency are very important as the ... Make sure every function including paging support, line I/O, ... Staying on the existing platform is always an option, ...
    (comp.sys.unisys)
  • Re: CE 6.0 Remote Tools - How to use? Platform Manager not recommended!
    ... Verified that "Target Control Support" catalog item is indeed checked ... Transport and Startup Server in "Configure Windows CE Platform ... #1 - Microsoft ActiveSync and KITL Bootstrap Server combo seems ... "Unable to establish connection with device. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Porting from CE to Desktop
    ... when run against the .NET Framework. ... Do you know if this provides debug capabilities across both platforms? ... once you chose a mobile platform, ... The .NET CF target builds your assemblies with the retargetable ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Lots of 2s
    ... the platform I mainly use, at the time the backend code is executed, does ... will override the GET value, and if not, raise a support call on it. ... This directive describes the order in which PHP registers GET, POST, Cookie, ...
    (uk.misc)