04 CREATING PROJECTS TO START DEVELOPMENT (for WPF apps) - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki
Any application has two main parts:
- Client side
- Server side
This presentation explains how to create projects for the client and server sides.
- Let's start by organizing folders:
-
Suppose, the root folder name for all projects will be
C:\Development\WpfDemo
-
Creating C# projects for the Client side.
Creating Blank Solution.
- Run Visual Studio
- Click File/New/Project menu item
- In the dialog select “Blank Solution” and click “next”
- Enter “WpfDemo” for the Solution name
- Select “C:\Development\” for the location
- Click “Create”
Creating "ServerProjects" Solution folder.
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click the solution node and select “Add/New Solution Folder”-menu item
- name the folder as "ServerProjects"
Creating "ClientProjects" Solution folder.
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click the solution node and select “Add/New Solution Folder”-menu item
- name the folder as "ClientProjects"
Creating "ClientProjects/Shared" Solution folder.
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click "ClientProjects"-folder of the solution node and select “Add New Project”-menu item
- name the folder as "Shared"
Creating "ClientProjects/Models" Solution folder.
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click "ClientProjects"-folder of the solution node and select “Add New Project”-menu item
- name the folder as "Models"
Creating C# project for Common Interfaces (Client side).
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click "ClientProjects/Shared"-folder of the solution node and select “Add New Project”-menu item
- In the dialog select “Class library (.Net Framework)” and click “next”
- Enter “CommonInterfacesClassLibrary” for the Project name
- Click “Create”
Creating C# project for Common Wpf Custom Controls (Client side).
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click "ClientProjects/Shared"-folder of the solution node and select “Add New Project”-menu item
- In the dialog select “Wpf custom control library (Net Framework)” and click “next”
- Enter “CommonWpfCustomControlLibrary” for the Project name
- Click “Create”
Creating C# project for Common Wpf User Controls (Client side).
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click "ClientProjects/Shared"-folder of the solution node and select “Add New Project”-menu item
- In the dialog select “Wpf User control library (Net Framework)” and click “next”
- Enter “CommonWpfUserControlLibrary” for the Project name
- Click “Create”
Creating C# project for Common Services Prism Module (Client side).
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click "ClientProjects/Shared"-folder of the solution node and select “Add New Project”-menu item
- In the dialog select “Prism module (Wpf)” and click “next”
- Enter “CommonServicesPrismModule” for the Project name
- Click “Create”
Creating C# project for Model Interfaces (Client side).
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click "ClientProjects/Shared"-folder of the solution node and select “Add New Project”-menu item
- In the dialog select “Class library (.Net Framework)” and click “next”
- Enter “ModelInterfacesClassLibrary” for the Project name
- Click “Create”
Creating C# project for Model Services Prism Module (Client side).
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click "ClientProjects/Models"-folder of the solution node and select “Add New Project”-menu item
- In the dialog select “Prism module (Wpf)” and click “next”
- Enter “ModelServicesPrismModule” for the Project name
- Click “Create”
Creating C# project for Feature Services Prism Module (Client side).
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click "ClientProjects/Models"-folder of the solution node and select “Add New Project”-menu item
- In the dialog select “Prism module (Wpf)” and click “next”
- Enter “FeatureServicesPrismModule” for the Project name
- Click “Create”
Creating C# project for Prism Demo App (Client side).
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click "ClientProjects"-folder of the solution node and select “Add New Project”-menu item
- In the dialog select “Prism blank app (Wpf)” and click “next”
- Enter “PrismDemoApp” for the Project name
- Click “Create”
- "Prism Project Wizard"-dialog will be shown
- Select "Unity" and click "Create project"-button
Preliminary result.
PREPARATION STEPS AFTER CREATING PROJECTS (Client side).
-
Step #0:
- Run Visual Studio 2019
- Open the “XamarinDemo” solution, which is located in the folder:
- C:\Development\XamarinDemo
- Right Click Solution Node and select "Manage NuGet Packages"
- Check "Select All Packages"
- Click "Update"
-
Step #1:
- Run Visual Studio 2019
- Open the “WpfDemo” solution, which is located in the folder:
- C:\Development\WpfDemo
- Remove "Class1.cs" from each project:
- CommonInterfacesClassLibrary
- ModelInterfacesClassLibrary
-
Step #2:
- Run Visual Studio 2019
- Open the “WpfDemo” solution, which is located in the folder:
- C:\Development\WpfDemo
- Remove "ViewModels" and "Views" folders from each project:
- FeatureServicesPrismModule
- ModelServicesPrismModule
- CommonServicesPrismModule
-
Step #3:
- Run Visual Studio 2019
- Open the “WpfDemo” solution, which is located in the folder:
- C:\Development\WpfDemo
- Remove "CustomControl1.cs" from project:
- CommonWpfCustomControlLibrary
-
Step #4:
- Run Visual Studio 2019
- Open the “WpfDemo” solution, which is located in the folder:
- C:\Development\WpfDemo
- In the "Themes/Generic.xaml"-file of "CommonWpfCustomControlLibrary"-project remove Style definition of CustomControl1.cs
-
Step #5:
- Run Visual Studio 2019
- Open the “WpfDemo” solution, which is located in the folder:
- C:\Development\WpfDemo
- Remove "UserControl1.xaml" from project:
- CommonWpfUserControlLibrary
-
Step #6:
- Open the “WpfDemo” solution
- Add reference to
- System.ComponentModel.DataAnnotations
- to each project:
- ModelServicesPrismModule
- CommonInterfacesClassLibrary
- CommonServicesPrismModule
- ModelInterfacesClassLibrary
-
Step #7:
- Open the “WpfDemo” solution
- Add reference to projects
- CommonInterfacesClassLibrary
- to each project:
- FeatureServicesPrismModule
- ModelServicesPrismModule
- CommonServicesPrismModule
- CommonWpfCustomControlLibrary
- CommonWpfUserControlLibrary
- PrismDemoApp
-
Step #8:
- Open the “WpfDemo” solution
- Add reference to projects
- CommonWpfCustomControlLibrary
- to each project:
- CommonWpfUserControlLibrary
- FeatureServicesPrismModule
- ModelServicesPrismModule
- CommonServicesPrismModule
- PrismDemoApp
-
Step #9:
- Open the “WpfDemo” solution
- Add reference to projects
- CommonWpfUserControlLibrary
- to each project:
- FeatureServicesPrismModule
- ModelServicesPrismModule
- CommonServicesPrismModule
- PrismDemoApp
-
Step #10:
- Open the “WpfDemo” solution
- Add reference to projects
- ModelInterfacesClassLibrary
- to each project:
- FeatureServicesPrismModule
- ModelServicesPrismModule
- PrismDemoApp
-
Step #11:
- Open the “WpfDemo” solution
- Add NuGet Package Reference
- Newtonsoft.Json
- to project:
- CommonInterfacesClassLibrary
- CommonServicesPrismModule
- ModelServicesPrismModule
- ModelInterfacesClassLibrary
-
Step #12:
- Open the “WpfDemo” solution
- Add NuGet Package Reference
- AutoCompleteTextBox (https://github.com/quicoli/WPF-AutoComplete-TextBox)
- to project:
- ModelServicesPrismModule
-
Step #13:
- set output folder: "..\PrismDemoApp\bin\Debug"
- for projects:
- FeatureServicesPrismModule
- ModelServicesPrismModule
- CommonInterfacesClassLibrary
- CommonServicesPrismModule
- CommonWpfCustomControlLibrary
- CommonWpfUserControlLibrary
- ModelInterfacesClassLibrary
-
Step #14:
- Open the “WpfDemo” solution
- Add reference to
- PresentationCore
- to each project:
- CommonInterfacesClassLibrary
-
Step #15:
- Open the “WpfDemo” solution
- Open "ModelServicesPrismModuleModule.cs"-file of "ModelServicesPrismModule"-project
- Remove deprecated "using xxx;"-operators
- Open "FeatureServicesPrismModuleModule.cs"-file of "FeatureServicesPrismModule"-project
- Remove deprecated "using xxx;"-operators
- Open "ModelServicesPrismModuleModule.cs"-file of "ModelServicesPrismModule"-project
- Open the “WpfDemo” solution
Creating C# projects for the Server side.
- CS2WPF is solution level tool. So, let's create four projects, one for each type of object (Only for cross-project demonstration):
- Dm01Entity for Entities Framework Entity classes
- Dm02Context for Entities Framework DB Context Classes
- Dm03Views for Views (or ViewModels)
- Dm04WebApp for Web-Api services
Creating Blank Solution.
- Run Visual Studio
- Click File/New/Project menu item
- In the dialog select “Blank Solution” and click “next”
- Enter “WpfDemo” for the Solution name
- Select “C:\Development\” for the location
- Click “Create”
Creating "ServerProjects" Solution folder.
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click the solution node and select “Add/New Solution Folder”-menu item
- name the folder as "ServerProjects"
Creating "ClientProjects" Solution folder.
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click the solution node and select “Add/New Solution Folder”-menu item
- name the folder as "ClientProjects"
Creating C# project for Entity classes (Server side).
- Dm01Entity for Entities Framework Entity classes:
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click "ServerProjects"-folder of the solution node and select “Add New Project”-menu item
- In the dialog select “Class library (.Net Framework)” and click “next”
- Enter “Dm01Entity” for the Project name
- Click “Create”
Creating C# project for Entity Framework Dbcontext classes (Server side).
- Dm02Context for Entity Framework dbcontext classes:
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click "ServerProjects"-folder of the solution node and select “Add New Project”-menu item
- In the dialog select “Class library (.Net Framework)” and click “next”
- Enter “Dm02Context” for the Project name
- Click “Create”
Creating C# project for Views(or ViewModels) classes (Server side).
- Dm03Views for for Views (or ViewModels) :
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click "ServerProjects"-folder of the solution node and select “Add New Project”-menu item
- In the dialog select “Class library (.Net Framework)” and click “next”
- In the dialog select “Class library (.Net Framework)” and click “next”
- Enter “Dm03Views” for the Project name
- Click “Create”
Creating C# projects for Web-Api services (Server side).
- Dm04WebApp for Web-Api services:
- Run Visual Studio
- Open “WpfDemo” solution
- In the Solution Explorer right-click "ServerProjects"-folder of the solution node and select “Add New Project”-menu item
- In the dialog select “Asp.Net Web Application (.Net Framework)” and click “next”
- Enter “Dm04WebApp” for the Project name
- Click “Create”
- On the “Create a New Asp.Net Web Application”-dialog
- Select Web Api
- Under “Authentication” click change and select
- Individual user account
- Click “Create”
PREPARATION STEPS AFTER CREATING PROJECTS
-
Step #1:
- Run Visual Studio 2019
- Open the “WpfDemo” solution, which is located in the folder:
- C:\Development\WpfDemo
- Remove "Class1.cs" from each project:
- Dm01Entity
- Dm02Context
- Dm03Views
-
Step #3:
- Run Visual Studio 2019
- Open the “WpfDemo” solution, which is located in the folder:
- C:\Development\WpfDemo
- Add “Literature” folder to each project:
- Dm01Entity
- Dm02Context
- Dm03Views
-
Step #4:
- Open the “WpfDemo” solution
- Add reference to
- System.ComponentModel.DataAnnotations
- to each project:
- Dm01Entity
- Dm02Context
- Dm03Views
-
Step #5:
- Open the “WpfDemo” solution
- For Dm02Context project add the following NuGet package:
- EntityFramework
- For Dm03Views project add the following NuGet package:
- Newtonsoft.Json
- For Dm04WebApp project add the following NuGet package:
- Microsoft.AspNet.WebApi.Cors
-
Step #6:
- Open the “WpfDemo” solution
- In Dm04WebApp project open file:
- App_Start\WebApiConfig.cs
- Add “using”:
- using System.Web.Http.Cors;
- In the body of the “Register” method add:
config.EnableCors(new EnableCorsAttribute("*", headers:"*", methods:"*"));
- In Dm04WebApp project open file:
- Providers\ApplicationOAuthProvider.cs
- In the body of the “GrantResourceOwnerCredentials” method add:
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
-
Step #7:
- It is highly recommended to install in your network or virtual environment the following software:
- MSSQL 2019 Developer Edition (Free Server)
- SQL Server Management Studio 18.5 (Free Studio)
- It is highly recommended to install in your network or virtual environment the following software: