Introduction:
Have you ever use two commands "Exclude & Include" in your Solution Explorer?.if yes good,these two commands having most importance.Because when we developing a big app,in solution explorer there may be some waste of files/images which are not useful at present,but in future these are may be useful.In this case we can temporarily remove un-useful item from the project using Exclude command.And in future when it needs we can add that item using Include command.Real time example:
I have done one project .After some other client ask same functionality with different theme,images ,app icons,app title that's all.In generally we can do it by renaming the existing project and replace all images,theme image,app icon &title and finally changing the product id of existing project from WMAppManifest.xml .that's all its simple to create new project,but when 50 clients asking same functionality with different theme,images?
oh what we can do ?
is it previous solution is good for this case? No it is very complicated to replace all images with existing ones.And we need to have proper documentation for "How to simply do 50 apps with same project without creating new project?".Here simply to understand the sample, i am taken two screens (MainPage & SecondPage),in MainPage there is one image control along with one button to navigate to SecondPage.And SecondPage is having back button to navigate back to MainPage. So this is the functionality and all 50 clients want same functionality with different images,theme,app title.See below image to understand the sample.
1)I have three client apps (Client1,Client2--Client50)
Note: In general a client doesn't ask same functionality which is already done in other apps,but this case is when we developing same app and sale it to our different customers as per their UI looks.So this sample may be useful for you in future.But for me i am working on this kind of project,so i just share it to my dear blog visitors to know about "How to create more different apps with same solution project "
Building the sample:
This sample is targeted on windowsphone 8.0 OS,however this solutino is also applicable for below versions.
Description:
I hope previously you understand this article requirement,so i don't waste of time and direclty lets start to do with simplicity.And this post gives us solution to "How to simply do 50 apps with same project without creating new project?".So i done this requirement with only two classes along with help of "Exclude & Include" commands.So lets start to knowing about these two commands.
2.Change productid id to
For example if we want to run Client50 app see in above image for Client50,
Exlcude:
With this command we can temporarily remove an item from the project. After excluding the file, you can still see it in Solution Explorer by clicking Show All Files.
To temporarily exclude an item that represents a file
- In Solution Explorer, select the item you want to exclude.
- On the Project menu, select Exclude From Project.
Note: Most advantage of exclude command is after exclude item ,it will not added in our app build file,so this way we can reduce our file size.and it just temporarily disassociate an item from a project without permanently removing it from project.
Include:
when needed excluded file ,we can include it to your project by using the Include in Project command.
To include an item that represents a file
- In Solution Explorer, select Show All Files.
- Select the item
- On the Project menu, select Include in Project.
Solution:
In earlier we learn the two commands (Exlude & Include).Now we start to knowing how these two commands are useful in our sample?.Instead of creating new project for new client.I had done all client apps with same project with following steps.
1.Copy the WMAppManifest.xml file and paste three times it to project solution ,after we will found 3 files 'Copy of WMAppManifest.xml' file just rename it to
- "WMAppManifest.xml_Client1",for Client1 APP.
- "WMAppManifest.xml_Client2",for Client2 APP.
- "WMAppManifest.xml_Client50",for Client50 APP.
2.Change productid id to
- '{68c7cf4c-37c2-4272-beb8-6a1ef0b3e7c1}' in WMAppManifest.xml_Client1 file for Client1 APP.
- '{68c7cf4c-37c2-4272-beb8-6a1ef0b3e7c2}' in WMAppManifest.xml_Client2 file for Client2 APP.
- '{68c7cf4c-37c2-4272-beb8-6a1ef0b3e7c50}' in WMAppManifest.xml_Client50 file for Client50 APP. (Because of every app is differentiate with its product id.so if you change a digit in it,then it will be treated as new app)
3.Create three image folder for (Client1_Images,Client2_Images,Client50_Images),and paste corresponding client images into folders with same names.
4.Create one Document folder and add textfile with name "Notes.txt",beacuse it is useful for note any changes in particular client app.and it is not a development part,its only for future reference and clear for any confusions.And exclude it from project,becuase of no use in development
5.Create class name is 'GetAPPID.cs' to get current targeted appid images
C#
public class GetAPPID { public string appID { get { //Getting current app id return (from manifest in System.Xml.Linq.XElement.Load("WMAppManifest.xml").Descendants("App") select manifest).SingleOrDefault().Attribute("ProductID").Value; //(or) // var appId = Windows.ApplicationModel.Store.CurrentApp.AppId; it is not working windowsphone 7 } } public string BgImage { get { return "BgImage.png";//for background image in a page } set { } } public string RoseImage { get { return "RoseImage.JPG";//for rose image in a page } set { } } public string Backbtn { get { return "Backbtn.png";//for back button image in a page } set { } } }
6.Create one converter class name is 'ImageSupplier.cs',which is useful for getting page images based on current appid .
C#
public class ImageSupplier : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string fileName = ""; GetAPPID GPD = new GetAPPID(); if (GPD.appID.ToString() == "{68c7cf4c-37c2-4272-beb8-6a1ef0b3e7c1}")//checking appid for client1 { fileName = string.Format("/Client{0}_Images/{1}", "1", value.ToString());//this is for retrieving corresponding client1 Images } else if (GPD.appID.ToString() == "{68c7cf4c-37c2-4272-beb8-6a1ef0b3e7c2}")//checking appid for client2 { fileName = string.Format("/Client{0}_Images/{1}", "2", value.ToString());//this is for retrieving corresponding client2 Images } else if (GPD.appID.ToString() == "{68c7cf4c-37c2-4272-beb8-6a1ef0b3e750}")//checking appid for client50 { fileName = string.Format("/Client{0}_Images/{1}", "50", value.ToString());//this is for retrieving corresponding client50 Images } if (targetType == typeof(Brush)) { BitmapImage bitmap = new BitmapImage(new Uri(fileName, UriKind.Relative)); ImageBrush brsh = new ImageBrush(); brsh.ImageSource = bitmap; return brsh; } else { return fileName; } } public object ConvertBack(object value, Type targetType, object parameter,System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } }
7.Reference above converter class in App.xaml ,to make it for all pages
8.And use in your MainPage for layout background like this way.
9.Wow now we are done almost 3 apps with only one project.Just we need to play for which client project should be run at present with "Exclude and Include" commands like this.
XAML
<xmlns:BgCoverter="clr-namespace:ExcludeIncludeWP"/> <Application.Resources> <BgCoverter:ImageSupplier x:Name="ImageConverter"></BgCoverter:ImageSupplier> <BgCoverter:GetAPPID x:Name="currentappid"></BgCoverter:GetAPPID> </Application.Resources>
XAML
<Grid x:Name="LayoutRoot" Background="{Binding Path=BgImage,Source={StaticResource currentappid}, Converter={StaticResource ImageConverter}}" > <!-- TO DO--> </Grid>
Client1 Client2 Client50
For example if we want to run Client50 app see in above image for Client50,
- we just include "WMAppManifest.xml_Client50" and rename it to "WMAppManifest.xml" .And don't forgot to exclude remaining manifest files "WMAppManifest.xml_Client1 & WMAppManifest.xml_Client2".beacuse of these two are not in use at present.
- And final step is include the "Client50_Images" folder for client50 images. Here we need to exclude remaining image folders (Client1_Images & Client2_Images),because of these two are not in use at present.Like this way we run and making build file of corresponding client app and excluding remaining items from project.
Source file at: ExcludeIncludeWPSample
No comments:
Post a Comment