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

Sharing code between projects


  • Please log in to reply
7 replies to this topic

#1 drischar

drischar

    Member

  • Members
  • PipPip
  • 13 posts

Posted 20 March 2012 - 06:47 AM

I'm working on a project that requires the Netduino to send data over a serial bluetooth connection (using Sparkfun's bluesmirf module). I've got the hardware working fine, but I am having a little trouble on the software side of things. The data I send over the serial connection is a specifically formatted packet, I have code that reads and writes these packets (basically a poor man's serialization since .net micro doesn't support it). I'd like for my solution to have two projects, one build using the .net framework (normal) and the other being the netduino project. I'd like to share one "class library" between the two that describes the packet protocol. Of course, if I create either a .net or .net micro class library, the other project will not let me reference it, and I can't add the files to the projects directly as Visual Studio will make copies of them. Is there a way to produce shared code files? Sort of like I could have some shared headers for a c++ project, without having to build something like a DLL first?

#2 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 20 March 2012 - 10:49 AM

Scrub that, I misread the question.

So some of your source code is identical, in both types of projects, so you only want to maintain one copy of it. Is that what you want?

You definitely can't share the compiled code, but I don't think there is any reason that you can't share the source code, if you can get it to compile in both types of projects. You might have to use a lot of ifdefs or whatever C# has for conditional compilation.

I think you would be better off having two solutions and cutting and pasting any similar code.
That way you can have two instances of visual studio and can debug both at the same time.

Edited by Magpie, 20 March 2012 - 11:07 AM.

STEFF Shield High Powered Led Driver shield.

#3 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 20 March 2012 - 04:08 PM

... I can't add the files to the projects directly as Visual Studio will make copies of them.

In "Add Existing Item..." dialog you can click the small drop-down arrow in the "Add" button and select "Add as Link".
  • unexpectedly likes this

#4 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 20 March 2012 - 06:20 PM

In "Add Existing Item..." dialog you can click the small drop-down arrow in the "Add" button and select "Add as Link".

And use #if where you have using statements which are different between the platforms.

Regards,
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#5 janicesmith954

janicesmith954

    New Member

  • Members
  • Pip
  • 1 posts

Posted 07 July 2012 - 12:20 AM

In "Add Existing Item..." dialog you can click the small drop-down arrow in the "Add" button and select "Add as Link".

Honestly, I am new to this. But yes what I did was I did the same with what you suggested here CW2. Also, I have been resourcing some resources about it. I also found this tutorial http://stackoverflow...n-visual-studio and also my friend is a wordpress developer so I also asked him for help.

#6 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 07 July 2012 - 08:28 PM

This is a bit off topic, but I thought I would pass along my tale of woe. I use the express editions of Visual Studio and simply allowed the default location <user>\Documents\Visual Studio 2010\ for projects. I made the mistake of copying the entire Documents folder to an external hard drive. Somehow, the permissions (or something in a configuration file) on the folder, C:\Users\baxter\Documents\Visual Studio 2010, got changed by the system with the net effect that I could not compile anything under this root. When trying to compile a program I would get the message, Error 1 Access to the path 'C:\Users\baxter\Documents\Visual Studio 2010\Projects_VB_Windows\Terminal\Terminal\obj\x86\Release\GenerateResource.read.1.tlog' is denied. All of the files in Solution Explorer were marked with a small yellow triangle containing an exclamation mark. Starting Debug would give the message, "there were build errors would you like to run the last successful build?" If I would click yes, the program would run ok. If I would save the Project after this debug step and reload it, it's was back to square zero. This would also occur with the external drive backup project folder. The properties of the Visual Studio folder were marked as read only and the permissions were ok. Unchecking read-only and applying had no effect at all; the system would just change it back. I tried all of the remedies I could find (e.g. giving Everyone full control, ATTRIB, iCACLS, takeown), but with no luck. After searching for a couple of days, I finally found a clue here, http://stackoverflow...n-visual-studio After a bit of trial and error, I finally stumbled on to the following procedure for recovery, 1. Delete the sln, suo files and bin, obj folders in the project directory from Windows Explorer 2. Double click on the vbproj file to load into VB 3. Build the project. It should build ok. 4. For each file marked with a yellow triangle in Solution Explorer, right click the Project Name --> Add --> Existing Item and add the file. Do this for each file and the marks will disappear. 5. Build again for good measure. Then --> Save All. When the project is saved and reloaded the triangles are still there, but the Project builds and debugs ok if there are no errors. If there are coding errors in the project, the errors will be flagged as usual, but after correction of the errors the file with the corrected errors cannot be saved (apparently because of the yellow triangles). To make the final restoration, open Windows explorer on the project and for each file right click for Properties and uncheck Hidden --> Apply. Once this last step is performed, the yellow triangles will have disappeared upon reloading the project. Actually, this should be step 6. Just check each file in the project for the hidden attribute and uncheck it. I have followed this procedure for two projects and they seem to be back to normal. I still no not know how this happened because I have backed up the Document folder before. If this happens to you, it will surely ruin your day. Baxter

#7 awaiK

awaiK

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts

Posted 11 August 2012 - 09:21 AM

Hi,

Project Linker is a little Visual Studio Extension which helps to link source files between projects.
Download: Project Linker
Documentation: Project Linker: Synchronization Tool
  • unexpectedly likes this

#8 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 18 August 2012 - 12:56 PM

Alternatively you could create a "Common" project then reference that in both projects you want the class in, i find that works well for maintaining helpers and utilities, as i generally find that i would want the helper at both ends of a transmission. It may seem overkill to add a third project when you solution consists of 2 projects, but its a real time saver when you start having more than 2 projects, also i try and reuse POCO's as much as possible, in one of my projects i share a "core" project with my nd project, a MVC 3 application and a whole bunch of Business Logic Layers Nak.




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.