I'm working in constrained environment (win7 under VirtualBox), and everything works excellent, except emulator (debug on real phone is OK). But I'm new to Visual Studio and .NET, and would like to develop all logic (at least interaction with web, algorithms, data models) in separate library (to test it against simple console or WPF application).
But here problems come — WP7 library uses special solution (and all projects by default are built against .NET Framework 4, when phone runs with .NET CF 3.7, why?). How I should setup IDE, to build crossplatform (I mean desktop/windows phone 7) library?
You can create parallel projects (one for desktop, one for phone) and add your c# files to one of them and link them in the other project.
To add a link to a file instead of copying it follow these steps:
Right click on the project => add existing item -> Select the file -> click the drop down arrow next to the "Add" button and chose "Add as Link".
To solve any incompatibility you can define a conditional compilation symbol like PHONE and wrap your incompatible code in:
#if PHONE
//phone code
#else
//desktop code
#endif
The downside is after you add a new code file in a project you need to link it from the corespondent project of the other platform.
I don't think there is a easier way of doing this.
You could use the MVVM pattern to develop your viewmodels (the business logic) in one assembly, then when you are ready for the UI, you can create a WP7 project and create the views inside that project, referencing the view models in the first project.
This would allow you to unit test and develop all your logic first, then just create the views and bind to the appropriate properties on the appropriate viewmodels.
MVVM was designed to be able to develop like this, so it works really well IMHO.
An acquaintance of mine suggested to use Portable Library Tools, which allows creation portable library for multiple target platforms (xbox, winphone7, silverlight, etc) without recompilation. Looks very promising.
Related
I am searching a way to brand application for different customers. Android Studio build system, Gradle, offers a mechanism of flavors, which allows replacing resource or code files, depending on selected application version. This allows easily achieve such features as branding application or creating lite and pro versions.
The simplest way (I imagine) I can do the same in Visual Studio with Xamarin is to create different source control branches in the project, but unfortunately this solution is quite hard to maintain: every change must be manually merged with all branches before deployment.
Is there another specific mechanism meant for this task?
I am currently working on porting an existing wpf app to a universal windows app.
The existing application is fairly simple and is structured as a normal wpf project, containing the ui layer and filesystem interactions, and a class library containing the main application logic.
I was able to transfer the class library to a Universal Windows Library (windows 10 sdk) without making any substantial changes. This Universal Windows library exists in its own project inside the same solution as the original wpf application.
In order to minimize complexity, I would like both the upcoming Universal Windows app and the wpf app to reference the same library. However I am unable to add a reference to the universal Windows library from my wpf project. The library appears in the "add reference" dialog in visual studio, but after selecting the library and clicking OK, I am presented with a message saying that the reference could not be added.
Is what I am trying to do currently not possible, or is there something I'm missing? It seems foolish to need to save the same code into two different library projects for it to be usable.
You should be able to select the target frameworks of the class library by right clicking the project > Properties > Library and under targeting hit change, and select .Net framework X on your machine. Then, (aside from incompatible API's in your PCL) you'll be able to reference the project
I've created a WPF project using MVVM pattern and another project for a web service.
In my WPF project, i've some views and I can navigate between them, everything works.
Now, I want to create a setup with InstallShield, I add project outputs, etc... but when I install the application, the buttons in the main view are not working as if the viewmodels were not include in the setup.
Any ideas ?
Thanks.
Where your installation does not give you the correct results, ask yourself the following questions. Move to the next if you answered 'yes'. If no, then that is a good starting point for your investigation:
Does it work in Release mode on your development PC?
Did the installed application load?
Are all your project outputs present in the installation directory?
Are all the installed files the right version?
Are your configuration files valid?
Have the correct version of the dependencies been installed? (.net version, etc)
Usually it is recommended to have two projects for both wp7 and wp8 platforms. Wp7 project contains .cs and .xaml files, and WP8 project contains links to that files.
I think that there is no reason to compile non-platform specific business logic code twice, since it can be referenced to WP8 project.
I'm thinking about following solution structure:
Business logic dll compiled for wp7 (not a PCL)
UI comliled for wp8
UI comliled for wp7
Such application can be compiled and I can deploy it to device/emulator.
The question is: will this app pass certification in Windows phone store? Or it is necessary to recompile shared dll?
UPD:
My crazy idea was born after this steps:
Create new WP7 app (WindowsPhoneApplication1)
Create class library targeted to WP7 (WindowsPhoneClassLibrary1) Use it in WindowsPhoneApplication1
Use Upgrade to WP8 menu. WindowsPhoneApplication1 will be updated to WP8, but the referenced project will be still targeted to WP7!
Such app can be deployed to WP8 devices.
Unless you use a Portable Class Library, you'll need to have separate project files, and compile separately for WP7 and WP8.
Thanks to Claus,
I made some research, and it looks like the answer is - you can use such solution.
I didn't find related information in documentation, but here is a proof from one of MSFT tech. evangelists from Netherlands: link to blogpost
The basic idea is to move all our code that can be used from both our existing Windows Phone 7 app as well as the Windows Phone 8 build, which we will add soon, to a Common project in the solution. The bad thing about this approach is that we have to create the Common project as a Windows Phone 7 class library, which will be used in our Windows Phone 8 build. I haven’t really noticed any negative impact of this decision in my existing apps, but note that you will be referencing a Windows Phone 7 library in your Windows Phone 8 build.
So it is a possible, but not the best solution.
I took over a Windows Phone project which was previously targeting WP 7.1 platform, and with the recent announcement of the new platform it should target WP 8 as well.
My VS 2010 solution consists on several projects (Data access, Model, Tests and WP7 client app) and i am wandering on how to include support for WP8.
I have to note that the code-base is not compatible with WP8, due to usage of Toolkit controls and other 3rd party libraries targeted for WP7.1 specifically.
Also there is another problem with the Visual Studio versions - WP7.1 can work with VS 2010, but WP8 requires VS 2012. Should i move the whole code-base to VS 2012?
Any good advice on how to organize code-base in a most meaningful way in order to avoid duplication and possible painful maintenance?
I am thinking between one solution - multiple projects vs. multiple solutions - reusable projects approach. Code duplication (like two separate folders/solutions) should be the least possible approach (fallback).
The best thing to do is for you to upgrade all the projects to VS2012 in order to be able to support both WP versions (you'll still be able to open the WP7 project in VS2010 despite it being a VS2012 solution, 'cause it's backward compatible).
Regarding the best way to organize the code base, in my opinion you should create a Portable Library that supports both WP7 and WP8 and get all the common code base there (probably mainly the business logic, specially good if you're using a pattern such as MVVM). Not forgetting about the controls issue, you should probably have some different controls for WP8 'cause the screen sizes are not the same and you could get some more info available and use different controls. If you still want to use the same XAML code, have just one file in one of the projects and add that same file "As Link" in the other project you want to re-use it.
Finally, you can, and also probably should, use some conditional code compilation by making use of the #if directive.
Hope that this information helps, and if any code sample is needed, just say so and I'll try to gather something up.