C # - code compiler for .NET and CF.NET

I have the same project that needs to be compiled with .NET and Compact.NET Framework.

  • Can I create a C # compiler that compiles my project from both sides?
  • Some functions are missing in the CF.NET Framework, so I created it (creating classes that have exactly the same name and options as in the .NET Framework. If I destroy these classes with an attribute like [CF35], you can analyze the project and:

    • Use this class when compiling a project using CF.NET
    • Ignore this class when compiling a project using .NET

?

Thanks for all the constructive answers.

[EDIT]

I know a solution that consists of creating two projects that reference the same files. The problem is that you have to make up both manually each time. Moreover, when you add a file to one file, you need to open the second one and refer to it too, that it just went too far, and according to the fact that we are working a lot on the same project, I would like to do this part automatically.

Seems possible?


[EDIT 2] Everything works fine except for ... resource files!

So, to resume work, I have three projects:

  • development project (CF.NET)
  • release project (CF.NET 3.5), including all files through ""
  • release project (NET 3.5), including all files through ""

As said, everything works fine, but now my problem is to use resource files.

How to apply a method to use it?

  • When I use a development project, the resource file is correctly extracted
  • When I use two other projects, ResourceManager raises MissingManifestResourceException

Any idea?

+3
source share
4 answers

The main idea would be to decorate your code with #if compiler directives for each version of the framework?

#if CFNET // .net CF code #else // .net code #endif 

Here you have two options:

A) 1 project file with custom build settings

If you want to have everything in 1 csproj file, you will need to manually change it. Since this is an msbuild file, this is more of an msbuild problem. I suppose you will need to do the following:

  • Use 2 platform names: "NET" and "CF" (instead of the standard Any CPU or x86)
  • Define the constant CF (From now on Edit csproj):

    <PropertyGroup Condition="'$(Platform)' == 'CF'"> <DefineConstants>CF</DefineConstants> </PropertyGroup>

  • Import the correct build targets based on the platform you select:

    <Import Condition="'$(Platform)' == 'NET'" Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Condition="'$(Platform)' == 'CF'" Project="$(MSBuildToolsPath)\<CFtargets>.targets" />

    I do not know the target file name for CF, since I do not have it. It could be somewhere in C:\Windows\Microsoft.NET\**.targets

B) 2 project files, each of which contains the corresponding assembly configuration

As I initially pointed out, as well as some commentators noted, the best solution is to have two project files that you keep in sync. You can have the same source files in both project files.

So the idea would be (instead of manually copying the list of files each time) to

  • consider using T4 templates to synchronize the source files (and you have 2 solutions, so you won’t be asked to reload the whole solution every time) or
  • modify the two csproj files and use the wildcard pattern as follows:

    <Compile Include="**/*.cs"/>

+4
source

You will need to create different layout configurations for each and define a custom flag, such as USE_CF . Then wrap your custom classes with #if USE_CF and #endif so that they are ignored when compiling without this flag

+6
source

There is only one C # compiler, it emits the same IL for any platform. What is the difference between reference assemblies, you need to use CF versions for a project that is designed for CF, desktop versions for a project that is designed for .NET. This requires two projects. They can reference the same source code files. Adding CF-only source files is now, of course, no longer a problem.

Keeping projects in sync is a feature available in VS2010. Of course, for Silverlight, it makes no sense for the CF project, since it no longer supports it.

+4
source

the best way is to create a regular project class library (.NET) and add all your code. Then create a second class library project (.NET CF), but specify the code files from the first project (not copies, but links). Then you get 2 DLLs and you don't have to deal with the nasty ugly compiler directives. You get the desired result without additional work to support both projects. Obvisouly you need to be careful what you enter into the code, since .NET CF is limited compared to .NET. I do not know how to add links to files (shortcuts) using visual studio, but I open the proj file in notepad and use the relative paths to the files to be added. I used this method for .NET / .NET CF as well as .NET / Silverlight

Also, check out the Portable Library Tool CTP http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981/?localeName=ko-kr

+3
source

All Articles