how to maintain code for two sdk versions of windows phone - windows-phone-7

I am building an app for windows phone sdk 7.0 and 7.1, I want to have some extra features for 7.1, but I want to maintain only one code base for both, and only have some code appear if user's phone is 7.1.
I read about Shawn Wildermuth's post: http://wildermuth.com/2011/08/23/Maintaining_a_Project_with_Two_Windows_Phone_Versions. But I am not sure how to do "First off, I took my original project and created two solution folders and created the 7.1 projects as shown here" mentioned in the post.
Could someone help? or suggest other ideas?
Thank you.

The perfect solution is preprocessor directives

[Updated 11/5/2011: removed outdated information about the Marketplace. Thanks for the udpated info #johnforrest]
To do what Shawn is describing take your existing solution with your existing 7.0 project(s). Add a solution folder and name it "7.0". Move your existing 7.0 projects into that solution folder. Make another solution folder named "7.1". For each project in the 7.0 solution folder, create a new matching project in the 7.1 solution folder. These are Shawn's PhonyTools.7.1 and so on. Now follow his directions for populating the 7.1 projects with linked files that are linked from the 7.0 projects.
I find linked files to be a blessing and a curse. If you open the linked file in one project and edit it, Visual Studio does not alway know that the other project containing the linked file needs to be rebuilt. Lately, I've been finding that if I remember to then open the linked file in the other project I will get a warning that the file is opened in another project, but then VS recognizes that the file has changed and will rebuild the other project.
Preprocessor directives, as suggested by #KevinDTimm, don't solve the problem all by themselves, because you still need two different projects for the two different types of projects (7.0 and 7.1 apps or libraries). Additionally the different versions of the apps will reference different corresponding versions of assemblies.
Lastly, while we're on the topic of conditional compilation, don't forget the Conditional attribute, which is often a much better solution than using preprocessor directives. Bill Wagner gives a good description of the merits of the [Conditional] attribute in Effective C#, 2nd ed., item 4, p. 20. Enjoy!

Related

Is it possible to add a Manifest file to a project in VS2005 Academic Edition?

I'm working on a really old program for my employer that requires a manifest file. Unfortunately the project was developed in .Net 2.0 on VS 2005 (Academic Edition) and migrating/updating to a newer... whatever would be time consuming and the really not worth it.
I've found ways to add a manifest file to a .exe manually (which is kind of a headache and I would prefer to avoid that route if that is at all possible for me to automatically include a manifest file into the application? I've found a few things on it but the options they reference seem to be missing from the Academic Edition.
I've seen this direction but there doesn't seem to be a manifest tool node (or I'm doing it wrong, could be either one). I found some images the closest I could get was this:
And it's missing the Manifest node that was referenced.
Is this possible to do with Academic Edition, or am I just hosed into having to do it the Open .exe in VS/add as a resource method? If I have to do it that way, that's fine but if there's a better way then I would prefer the better way.

Assembly version clashes in visual studio/team foundation server

We recently split our current work into two different VS solutions, one which contains mainly the front-end stuff (aspx files, user controls and the like) and the other which contained mainly business logic to compile into assemblies and reference in the first solution.
Since doing this we've been experiencing problems with versioning when building the business logic solution and trying to check the new dll's into the front-end solution. Most of the dll's (and pdb files) say that a newer version exists on the server.
I'm confused about this because when I went looking in the AssemblyInfo files of the projects in the Business Logic solution, they all had no version number set except the default of 1.0.0.0. Building the solution is currently generating files with version 2.2.1.3 and the server apparently has version 2.2.2.3 but nowehere can I see where these version numbers are being generated. Changing and rebuilding a project doesn't seem to change the version number unless I manually edit the version number in the AssemblyInfo of that project.
Can anyone suggest a way we can move forward on this, so that all the projects in the solution automatically update to the same version number when the solution is built, regardless of which developer is doing the build?
Cheers,
matt
The version number has nothing to do with the version number in the dll, but with the version of the file in source control.
You are trying to check in a file from which you don't have the latest yet. So undo your change, get the latest version of the files. Then check them out again and check them in.

Visual Studio Project vs. Solution

Being new to VS, how may I think of these two concepts, what is the difference?
I find some missing information in the other answers (at least for people who come from other IDEs like, say, Eclipse) . To say that a solution is a container for projects is only part of the thing. The conceptual feature of a VS project (what determines its 'granularity') is that one project produces one output: typically an executable or a library (dll). So, if you are going to code three executables that uses related code, you'll create one solution and at least three projects - probably more.
A solution is a container for projects, and tracks dependencies between projects.
Just to come up with a metaphor..
A solution is like a house, a project like a room. Each room provides a piece of functionality whereas the house, a container of rooms, provides the means to link the rooms together and organize them appropriately.
Kind of corny but I made it up on the fly, so bear with me :)
It doesn't help that Visual Studio seems to make things more confusing. "New Project" actually creates a new SOLUTION containing a project. "Open Project" actually opens a solution containing one (or many) project. (The file menu says "Open Project/Solution" but it really is opening solutions. There is no "Close Project" only "Close Solution" which is accurate.
So, in VS you are always working within a solution. Many solutions contain only one project and newer developers are likely to think of them as the same thing. However you can add other projects into a solution.
In case anyone decides to scroll down this far... I thought the MS docs did a pretty good job at describing the differences. I've copy pasted (and rephrased) the relevant bits here:
When you create an app, application, website, Web App, script, plug-in, etc in Visual Studio, you start with a project. In a logical sense, a project contains of all the source code files, icons, images, data files and anything else that will be compiled into an executable program or web site, or else is needed in order to perform the compilation. A project also contains all the compiler settings and other configuration files that might be needed by various services or components that your program will communicate with.
You don't have to use solutions or projects if you don't want to. You can simply open the files in Visual Studio and start editing your code.
In a literal sense, a project is an XML file (.vbproj, .csproj, .vcxproj) that defines a virtual folder hierarchy along with paths to all the items it "contains" and all the build settings.
In Visual Studio, the project file is used by Solution Explorer to display the project contents and settings. When you compile your project, the MSBuild engine consumes the project file to create the executable. You can also customize projects to product other kinds of output.
A project is contained, in a logical sense and in the file system, within a solution, which may contain one or more projects, along with build information, Visual Studio window settings, and any miscellaneous files that aren't associated with any project. In a literal sense, the solution is a text file with its own unique format; it is generally not intended to be edited by hand.
A solution has an associated .suo file that stores settings, preferences and configuration information for each user that has worked on the project.
A Solution can have many Projects.
The Solution can also handle managing the dependencies between its different Projects...making sure that each Project gets Built in the appropriate order for the final Solution to work.
A project contains executable and library files that make up an application or component of an application.
A solution is a placeholder for logically related projects that make up an application. For example, you could have separate projects for your application's GUI, database access layer, and so on. The projects would be specific divisions for your program's functionality, and the solution would be the umbrella unifying all of them under one application.
A solution is a readable text file whose extension is .sln and having a structured content that describes the projects that it contains. A project is a readable XML formatted text file whose extension is .vcxproj and having a structured content according to its XML schema, and whose primary purpose is to contain the listing of source codes filenames and their dependencies or references to other project's source codes as well.
Solutions are containers for projects - you can also use them to organize items that are used across different related project (shared dll's and such).
Solutions are containers used by Visual Studio to organize one or more related projects. When you open a solution in Visual Studio, it will automatically load all the projects it contains.
When you create a new project in Visual Studio, it automatically creates a solution to house the project if there's not a solution already open.
You can set dependencies of projects on other projects in the solution. The dependent project is build after the project it is depending on is built.
For more details refer - https://learn.microsoft.com/en-us/visualstudio/ide/quickstart-projects-solutions
If you are from an Eclipse background you would probably go to build path of a project and add a dependency on other project or add an external jar. In VS you can do that in a single container called solution where all related projects are grouped together.
Eg. Let's say you are build and android and iOS app in xamrin, there would be some common code and resources that could go in a separate project and then your android and iOS projects can depend on this common code project. Also you could have projects to test these projects etc.

Find in Files or Quick Find in VS 2008 seems to only work sometimes?

I am working on a project using VS 2008, containing MANY files within projects
within solutions. We recently had to convert all our work from VS 2003 to 2008 (you know
how big companies are always the last to convert to the lastest version of stuff).
In trying a "Find in Files" (or "Quick Find") within 1 solution containing 3 projects, I am successful in my search within all 3 projects only when using "Current Doc" & "All Open Docs". But when using "Entire Solution" or "Current Project" only 2 of the 3 projects give me correct results. The Find will not show files within 1 project in particular that I KNOW include results from my Find.
After reading suggestions from:
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=105511
I attempted every Workaround they had, and NONE worked for me. Any suggestions???
Setting find options
First try the following:
Ctrl+Shift+F (Find In Files)
Look in: Entire Solution
Expand Find Options
Whatever for Match case
Whatever for Match whole word
Uncheck "Use:"
Look at these file types: *.*
"Dealing" with some rare solution hierarchy issues
Next, if you have your projects organized into solution folders (as in you have this instead of this), try expanding each of the projects one time, as follows:
foreach solution folder in the project
expand the solution folder
foreach project in the solution folder
• expand the project node
• (optional) collapse the project node
(optional) collapse the solution folder
Additional details regarding expanding the projects: in my work on my Solution File List tool pane (in particular the Find in Solution Explorer feature shown), I found that sometimes files aren't found in the solution if the project hasn't been expanded once. Using the automation model, the problem always occurs, but using the lower level COM interfaces is more likely to work. The lower level interfaces are what Visual Studio uses internally, so most of the time people won't run into this problem. I use a lot of carefully ordered operations (aka hacks) to keep it working as much as possible, but every once in a while I still have to expand a folder before a file is found.
If all else fails
I'll need to know as much of the following as you can provide. These are relevant for all projects in the solution, not just the ones that aren't working for the Find in Files. For some Visual Studio operations, an exception will interrupt the remainder of the operation, so an exception while operating on project A might keep the find from reaching project B, etc.
What project types do you have in the solution? Especially if you are using 3rd party project types such as VS.Php (I think .phpproj) or nFringe (.ucproj). As a quick check, you can right click each of those projects and select Unload Project, then try the Find In Files afterwards.
What source control system are you using?
Do you have any 3rd-party add-ins installed? (Microsoft ones count if they are power toys, etc.)
Do you have any non-file-system files in the project? (Nodes in the project that don't map directly to a file on the hard drive.)
Does any project in the solution reference files on the network?

Structuring projects & dependencies of large winforms applications in C#

UPDATE:
This is one of my most-visited questions, and yet I still haven't really found a satisfactory solution for my project. One idea I read in an answer to another question is to create a tool which can build solutions 'on the fly' for projects that you pick from a list. I have yet to try that though.
How do you structure a very large application?
Multiple smallish projects/assemblies in one big solution?
A few big projects?
One solution per project?
And how do you manage dependencies in the case where you don't have one solution.
Note: I'm looking for advice based on experience, not answers you found on Google (I can do that myself).
I'm currently working on an application which has upward of 80 dlls, each in its own solution. Managing the dependencies is almost a full time job. There is a custom in-house 'source control' with added functionality for copying dependency dlls all over the place. Seems like a sub-optimum solution to me, but is there a better way? Working on a solution with 80 projects would be pretty rough in practice, I fear.
(Context: winforms, not web)
EDIT: (If you think this is a different question, leave me a comment)
It seems to me that there are interdependencies between:
Project/Solution structure for an application
Folder/File structure
Branch structure for source control (if you use branching)
But I have great difficulty separating these out to consider them individually, if that is even possible.
I have asked another related question here.
Source Control
We have 20 or 30 projects being built into 4 or 5 discrete solutions. We are using Subversion for SCM.
1) We have one tree in SVN containing all the projects organised logically by namespace and project name. There is a .sln at the root that will build them all, but that is not a requirement.
2) For each actual solution we have a new trunks folder in SVN with SVN:External references to all the required projects so that they get updated from their locations under the main tree.
3) In each solution is the .sln file plus a few other required files, plus any code that is unique to that solution and not shared across solutions.
Having many smaller projects is a bit of a pain at times (for example the TortoiseSVN update messages get messy with all those external links) but does have the huge advantage that dependancies are not allowed to be circular, so our UI projects depend on the BO projects but the BO projects cannot reference the UI (and nor should they!).
Architecture
We have completely switched over to using MS SCSF and CAB enterprise pattern to manage the way our various projects combine and interact in a Win Forms interface. I am unsure if you have the same problems (multiple modules need to share space in a common forms environment) but if you do then this may well bring some sanity and convention to how you architect and assemble your solutions.
I mention that because SCSF tends to merge BO and UI type functions into the same module, whereas previously we maintained a strict 3 level policy:
FW - Framework code. Code whose function relates to software concerns.
BO - Business Objects. Code whose function relates to problem domain concerns.
UI - Code which relates to the UI.
In that scenario dependancies are strictly UI -> BO -> FW
We have found that we can maintain that structure even while using SCSF generated modules so all is good in the world :-)
To manage dependencies, whatever the number of assemblies/namespaces/projects you have, you can have a glance at the tool NDepend.
Personnaly, I foster few large projects, within one or several solutions if needed. I wrote about my motivations to do so here: Benefit from the C# and VB.NET compilers perf
I think it's quite important that you have a solution that contains all your 80 projects, even if most developers use other solutions most of the time. In my experience, I tend to work with one large solution, but to avoid the pain of rebuilding all the projects each time I hit F5, I go to Solution Explorer, right-click on the projects I'm not interested in right now, and do "Unload Project". That way, the project stays in the solution but it doesn't cost me anything.
Having said that, 80 is a large number. Depending on how well those 80 break down into dicrete subsystems, I might also create other solution files that each contain a meaningful subset. That would save me the effort of lots of right-click/Unload operations. Nevertheless, the fact that you'd have one big solution means there's always a definitive view of their inter-dependencies.
In all the source control systems that I've worked with, their VS integration chooses to put the .sln file in source control, and many don't work properly unless that .sln file is in source control. I find that intriguing, since the .sln file used to be considered a personal thing, rather than a project-wide thing. I think the only kind of .sln file that definitely merits source control is the "one-big-solution" that contains all projects. You can use it for automated builds, for example. As I said, individuals might create their own solutions for convenience, and I'm not against those going into source control, but they're more meaningful to individuals than to the project.
I think the best solution is to break it in to smaller solutions. At the company I currently work for, we have the same problem; 80 projects++ in on solution. What we have done, is to split into several smaller solutions with projects belonging together. Dependent dll's from other projects are built and linked in to the project and checked in to the source control system together with the project. It uses more disk space, but disk is cheap. Doing it this way, we can stay with version 1 of a project until upgrading to version 1.5 is absolutely necessary. You still have the job with adding dll's when deciding to upgrade to a other version of the dll though. There is a project on google code called TreeFrog that shows how to structure the solution and development tree. It doesn't contain mush documentation yet, but I guess you can get a idea of how to do it by looking at the structure.
A method that i've seen work well is having one big solution which contains all the projects, for allowing a project wide build to be tested (No one really used this to build on though as it was too big.), and then having smaller projects for developers to use which had various related projects grouped together.
These did have depencies on other projects but, unless the interfaces changed, or they needed to update the version of the dll they were using, they could continue to use the smaller projects without worrying about everything else.
Thus they could check-in projects while they were working on them, and then pin them (after changing the version number), when other users should start using them.
Finally once or twice a week or even more frequently the entire solution was rebuild using pinned code only, thus checking if the integration was working correctly, and giving testers a good build to test against.
We often found that huge sections of code didn't change frequently, so it was pointless loading it all the time. (When you're working on the smaller projects.)
Another advantage of using this approach is in certain cases we had pieces of functionality which took months to complete, by using the above approach meant this could continue without interrupting other streams of work.
I guess one key criteria for this is not having lots of cross dependencies all over your solutions, if you do, this approach might not be appropriate, if however the dependencies are more limited, then this might be the way to go.
For a couple of systems I've worked on we had different solutions for different components. Each solution had a common Output folder (with Debug and Release sub-folders)
We used project references within a solution and file references between them. Each project used Reference Paths to locate the assemblies from other solutions. We had to manually edit the .csproj.user files to add a $(Configuration) msbuild variable to the reference paths as VS insists on validating the path.
For builds outside of VS I've written msbuild scripts that recursively identify project dependencies, fetch them from subversion and build them.
I gave up on project references (although your macros sound wonderful) for the following reasons:
It wasn't easy to switch between different solutions where sometimes dependency projects existed and sometimes didn't.
Needed to be able to open the project by itself and build it, and deploy it independently from other projects. If built with project references, this sometimes caused issues with deployment, because a project reference caused it to look for a specific version or higher, or something like that. It limited the mix and match ability to swap in and out different versions of dependencies.
Also, I had projects pointing to different .NET Framework versions, and so a true project reference wasn't always happening anyways.
(FYI, everything I have done is for VB.NET, so not sure if any subtle difference in behavior for C#)
So, I:
I build against any project that is open in the solution, and those that aren't, from a global folder, like C:\GlobalAssemblies
My continuous integration server keeps this up to date on a network share, and I have a batch file to sync anything new to my local folder.
I have another local folder like C:\GlobalAssembliesDebug where each project has a post build step that copies its bin folder's contents to this debug folder, only when in DEBUG mode.
Each project has these two global folders added to their reference paths. (First the C:\GlobalAssembliesDebug, and then C:\GlobalAssemblies). I have to manually add this reference paths to the .vbproj files, because Visual Studio's UI addes them to the .vbprojuser file instead.
I have a pre-build step that, if in RELEASE mode, deletes the contents from C:\GlobalAssembliesDebug.
In any project that is the host project, if there are non dlls that I need to copy (text files outputted to other project's bin folders that I need), then I put a prebuild step on that project to copy them into the host project.
I have to manually specify the project dependencies in the solution properties, to get them to build in the correct order.
So, what this does is:
Allows me to use projects in any solution without messing around with project references.
Visual Studio still lets me step into dependency projects that are open in the solution.
In DEBUG mode, it builds against open loaded projects. So, first it looks to the C:\GlobalAssembliesDebug, then if not there, to C:\GlobalAssemblies
In RELEASE mode, since it deletes everything from C:\GlobalAssembliesDebug, it only looks to C:\GlobalAssemblies. The reason I want this is so that released builds aren't built against anything that was temporarily changed in my solution.
It is easy to load and unload projects without much effort.
Of course, it isn't perfect. The debugging experience is not as nice as a project reference. (Can't do things like "go to definition" and have it work right), and some other little quirky things.
Anyways, that's where I am on my attempt to make things work for the best for us.
We have one gigantic solution on the source control, on the main branch.
But, every developer/team working on the smaller part of the project, has its own branch which contains one solution with only few projects which are needed. In that way, that solution is small enough to be easily maintenaced, and do not influence on the other projects/dlls in the larger solution.
However, there is one condition for this: there shouldn't be too much interconnected projects within solution.
OK, having digested this information, and also answers to this question about project references, I'm currently working with this configuration, which seems to 'work for me':
One big solution, containing the application project and all the dependency assembly projects
I've kept all project references, with some extra tweaking of manual dependencies (right click on project) for some dynamically instantiated assemblies.
I've got three Solution folders (_Working, Synchronised and Xternal) - given that my source control isn't integrated with VS (sob), this allows me to quickly drag and drop projects between _Working and Synchronised so I don't lose track of changes. The XTernal folder is for assemblies that 'belong' to colleagues.
I've created myself a 'WorkingSetOnly' configuration (last option in Debug/Release drop-down), which allows me to limit the projects which are rebuilt on F5/F6.
As far as disk is concerned, I have all my projects folders in just one of a few folders (so just one level of categorisation above projects)
All projects build (dll, pdb & xml) to the same output folder, and have the same folder as a reference path. (And all references are set to Don't copy) - this leaves me the choice of dropping a project from my solution and easily switching to file reference (I've got a macro for that).
At the same level as my 'Projects' folder, I have a 'Solutions' folder, where I maintain individual solutions for some assemblies - together with Test code (for example) and documentation/design etc specific to the assembly.
This configuration seems to be working ok for me at the moment, but the big test will be trying to sell it to my colleagues, and seeing if it will fly as a team setup.
Currently unresolved drawbacks:
I still have a problem with the individual assembly solutions, as I don't always want to include all the dependent projects. This creates a conflict with the 'master' solution. I've worked around this with (again) a macro which converts broken project references to file references, and restores file references to project references if the project is added back.
There's unfortunately no way (that I've found so far) of linking Build Configuration to Solution Folders - it would be useful to be able to say 'build everything in this folder' - as it stands, I have to update this by hand (painful, and easy to forget). (You can right click on a Solution Folder to build, but that doesn't handle the F5 scenario)
There is a (minor) bug in the Solution folder implementation which means that when you re-open a solution, the projects are shown in the order they were added, and not in alphabetical order. (I've opened a bug with MS, apparently now corrected, but I guess for VS2010)
I had to uninstall the CodeRushXPress add-in, because it was choking on all that code, but this was before having modified the build config, so I'm going to give it another try.
Summary - things I didn't know before asking this question which have proved useful:
Use of solution folders to organise solutions without messing with disk
Creation of build configurations to exclude some projects
Being able to manually define dependencies between projects, even if they are using file references
This is my most popular question, so I hope this answer helps readers. I'm still very interested in further feedback from other users.

Resources