Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Compiling C# on the fly


  • Please log in to reply
5 replies to this topic

#1 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 26 January 2011 - 08:57 AM

Hi everybody! I wonder if there's any (reliable) way to compile parts of C# code and then send the PE to feed the board, *without* having/using VS installed. Think to an app running on the PC where the user may write simple functions in C#. Once the user has finished writing, he should press a button that compiles the code in PE format. That PE could be stored to the SD-card, for example. Any tip? Thanks in advance Mario
Biggest fault of Netduino? It runs by electricity.

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 January 2011 - 09:14 AM

Hi Mario, I believe that the .NET Framework comes with the C# compiler (and if not, the .NET SDK does). You should be able to accomplish this without installing any development environments on the end-user PC. And then loading the assembly from the SD card should be pretty straightforward. Fabien and a few other community members have been working on this... Chris

#3 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 26 January 2011 - 09:47 AM

I wonder if there's any (reliable) way to compile parts of C# code and then send the PE to feed the board, *without* having/using VS installed.

In addition to Chris' suggestion (externally running command line C# compiler csc.exe), you can also have a look at Microsoft Knowledge Base article 304655: How to programmatically compile code using C# compiler (includes 'button_click' sample code).

Once the user has finished writing, he should press a button that compiles the code in PE format.

The PE file is produced from the source assembly (.dll or .exe) by MetaDataProcessor.exe, which is a part of .NET Micro Framework SDK. It has numerous command line parameters, you can build a sample solution in Visual Studio to see its usage in Output window, it is basically in form metadataprocessor.exe -loadhints {assembly reference} -endian {le|be} -parse {source assembly} -minimize -compile {target PE}.

In more advanced scenarios, you could also use/generate .sln or .proj file and invoke MSBuild.exe (part of .NET Framework) with appropriate parameters. If you are interested in build details, you can inspect *.targets files in %Program Files%\MSBuild\Microsoft\.NET Micro Framework\v4.1\ directory.

#4 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 26 January 2011 - 11:08 AM

You could also upload the whole program to the board each time. Through MFDeploy. Eg. your own program stub could be compiled along with the user code. This means that you won't have to implement "load assembly" in your fw/program. It's easy to use the builtin compiler btw.

#5 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 26 January 2011 - 11:48 AM

Thanks everybody. @CW2 and Chris: I already know and I've tried a time ago the MS's article on how to compile a project by using another program. My doubt was about producing the PE: you know, my deal is a "one-click-programming" target. @Illishar: your tip is valuable also. In the truth I'd prefer to replace the whole application instead a single piece. That's avoiding mismatches, versioning problems, etc. By the way, I'm afraid about the potential consequences: if something's going wrong, will be the user able to rescue the board control? I'll manage some experiment, then we see... Thanks again. Mario
Biggest fault of Netduino? It runs by electricity.

#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 January 2011 - 07:09 PM

By the way, I'm afraid about the potential consequences: if something's going wrong, will be the user able to rescue the board control?


As long as the user hasn't changed the USB configuration on the board (using the UsbClient feature of .NET MF) then there's an easy backup: just hold the pushbutton on your Netduino while plugging it in and you can ERASE the current app via MFDeploy. Worst case scenario, you can also erase the board completely and reflash .NET MF.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.