Multiple Web Projects in a single ASP.NET Solution - c#

Is it really possible to have a two different asp.net web projects in a single web solution ? For instance here's the current structure
+Solution
-CoreModule
-CustomModule
-WebProject
In this same hierarchy, can I have this
+Solution
-CoreModule
-CustomModule
-WebProject
-NewWebProjectModule
And use the web pages defined on NewWebProjecModule inside WebProject and use the style defined in WebProject inside NewWebProjectModule ?
What I am trying to do is separate the modules in the web project to have less clutter ?
Or would I be better of doing a control library as different project OR have the business rules on a separate module and have the UI on the main web project ?

First, you can very much have more than one web project in a Visual Studio Solution. While debugging with VS, you will have to run the required one.
If you have contents/controls that get replicated/reused in both web projects, I would prefer to have them in a common library/module and use them as required.

Related

Debugging WebMethod()s - stepping into code from the calling project

I used a decompiler to retrieve lost source code for a set of web services written long ago. I want to debug the retrieved web methods using an existing web forms project. The two projects my solution contains are: 1) The recovered web services project and 2) The calling web forms project (created years ago) that references the live web services.
I created a project reference from the web forms project to the new web service project. My goal is make temporary changes in the calling code to allow me to step into each WebMethod using the project reference instead of the live web service reference. I'm hoping to debug the WebMethods as if I was debugging a standard class library.
The problem is that none of the WebMethods are visible using the project reference. Only the containing class is visible in the calling project but none of the Public Subs or Functions show via intellisense. How can I debug these WebMethods using the existing calling code from the web forms project?
Here is one of the simpler calling routines:
Private Sub LoadCountryCode()
Dim liveWebService As New EPriceBookWebService.Service1SoapClient
'Next line TEMPORARILY commented out for testing...
'liveWebService.GetCustomerCountry(lstbxCusCodes.SelectedValue, _countryCode)
'Project reference below shows only the web service class, not the contained public methods via intellisene. WHY?
EPriceBookService.EPriceBookService.
End Sub
Here is the stub of the WebMethod() being called:
<WebMethod()>
Public Sub GetCustomerCountry(ByVal CusCode As String, ByRef CountryCode As String)
I'm answering my own question here...
It was unwise for me to use a project reference to debug a web service project. Instead, I've learned how to debug the web service project from the calling web forms project (directly stepping into the code). To do this I made use of an obscure setting in the web service project called "Don't open a page. Wait for a request from an external application." You can turn on this setting from the project property pages under the Web category. I learned about the setting here and here.
My two projects are in the same solution. The web forms project now references two web services 1) the live web service and 2) the localhost web service in my solution. I've added compiler (preprocessor) directives to the web forms project telling it which web service reference to use.
#If DEBUG Then
Dim theWebService As New localhostEPricebookWebReference.EPriceBookService
#Else
Dim theWebService As New EPriceBookWebService.Service1SoapClient
#End If
Be sure you turn off debug mode before deploying your application.

How to access static content in an MVC Area?

I have an MVC Area in a second Project (part of a different solution) and I cannot seem to find any way of accessing its Static Content when running my website.
Project 1 contains a normal MVC application which works fine.
Project 2 contains simply an Area. Project 2 is using RazorGenerator to compile the views, this project is referenced by Project 1 and is not in the same solution.
In Project 2 within my Area is a Content Folder with static images and styles. How can I get the main website to serve this content? I presume that I cannot because RazorGenerator is not able to compile non code files.
http://forums.asp.net/t/1534837.aspx?Static+content+in+Areas
In articles like above people simply manipulate the URL but this is not working for me, I get 404 for all because its not in the same solution.
How can I get this static content in Project 2 to be accessible to Project 1 given that I am using RazorGenerator to compile my views? I am aiming to make a self contained Area that I can add to other projects without needing to copy files over to support it.

Devexpress xaf modules

Using devexpress 12.2.x
Lets say we create a cross platform application. SomeApp
The following projects are created:
SomeApp.Module
SomeApp.Module.Web
SomeApp.Module.Win
SomeApp.Web
SomeApp.Win
Now each of the .Module projects contains a xafml file.
So far I've only made changes in my SomeApp.Module project, but I've been wondering what would be the effect/purpose of making the changes in for e.g. SomeApp.Module.Win project. Basically whats the differences between those xafml files and when would I make changes in the one and not the other?
Refer to the Application Solution Structure
A application solution contains the following:
Windows Forms Application Project - Code, specific to the Windows Forms
version of your application.
Web Application Project - Code, specific to a browser-based interface.
Module Project - Use this assembly to implement UI-independent
application elements. For example, in it you can define a business
model. Subsequently, both the Windows Forms and ASP.NET Web
applications will have a similar business model.
Windows Forms Module Project - Use this assembly to implement
application elements for the Windows Forms application version. This
assembly is referenced in the Windows Forms application project only.
ASP.NET Web Module Project -
Use this assembly to implement application elements for the ASP.NET Web application version. This assembly is referenced in the
Web application project only.
Further Reading
XAF overlays the changes in the module difference files. The model applied to your application (that is, the model resulting from overlaying all the Model.DesignedDiffs.xafml - files in your modules) is the file Model.xafml in your main project(s) (SomeApp.Web, SomeApp.Win)
The question which adjustment should be made in which xafml-file is hard to answer. We have tried several solutions already, none is really perfect. A general rule of thumb could be: Adjustments to an element are applied to the xafml file of the module where the element is defined.
Sometimes, especially if you have a layered application, it could be that you will have to apply the same adjustment in two different modules (e.g.: Label of a data item on a product level could differ from that on a customer level) .
In Devexpress XAF applications have three main parts. Module, Module.Win.Control, Module.Win. Win.Control part include Module part and Win Part include Win.Control part.
So Model.DesignedDiffs.xafml files have same behavior.
If you change on module xafml, it affects other xafml files but you change win xafml file, it affects only itself. This structure is same like dll reference.

Multiple applications in single solution

I believe this is possible but unsure how to go around it, I need to create a server/client solution, normally I would create a new solution for the server and a new one for the client however I am looking to do this within a single solution as they would both be using the same custom classes and don't really want the issue of having to change the same file twice.
So the question is can I create multiple exe's within a single solution and what are the steps to achieve this.
I have searched on here but don't fully understand the procedure so if someone can point me in the general right direction it would be great. :)
VS2010 using C Sharp and Windows Forms
Please see this and this previous answer which I gave on cross-platform client server application development, specifically with code-reuse across multiple clients. This is also applicable to your Winforms client server app here.
As many answers are saying, you can structure your solution in order to share code as follows:
Project Structure
Solution
.. Common (Messages, Datacontracts, Utilities)
.. Middleware (References Common, provides common services)
.. .. Server Exe (References Common, Middleware)
.. .. Client Exe (References Common, Middleware)
Top level client-server architecture
Your stack becomes
Clients:
Client has serialization, client side implementations of webservices/middleware and Model-View-Presenter patterns for the view.
Middleware:
Middleware, i.e. shared services and data transport implemetation on server / client desktop can be the same. Alternatively you could call this Services. Any specific services for client only (or server only) should go in separate assemblies and referenced only by the specific exe (client or server). i.e. dont share code that isn't shared!
Messages/DataContracts:
Shared across all clients/server using the techniques I outlined above. In your case these may be common domain objects shared between client and server
Server:
All business logic, DB access and server-side service implementations. For DB Access I'd recommend PetaPoco as an excellent MicroORM.
Development and debugging
Yes, a solution can have more than one exe, simply use set Startup Project by right clicking on Server Exe or Client Exe to debug one or the other.
If you wish to run the client and server together, you can run both from the command line and attach the debugger to both processes.
Best regards,
First, ensure you can see the solution file in the solution explorer:
Go to Tools->Options. Then under Projects and Solutions ensure Always Show Solutions is checked.
Then, in the solution explorer (top right, where your project's files are) right click on your solution (just above your project icon) then click Add->New Project.
In terms of the layout of the solution, you'd have 3 projects, the client project, the server project, and a class library project of shared classes.
Your client and server projects would reference the library project, see: Project Reference (MSDN)
See also: Multi-Project Solutions (MSDN)
You would do it like this:
Have one solution
Add three projects to the solution:
Project A: The server exe
Project B: The client exe
Project C: A class library project containing the classes that projects A and B use.
Make project A and B reference project C
You can right click on solution icon located at the top in the solution explorer and choose add new project option.
Add a new Class Library project to your solution. Put your common code in there.
Add as a many WinForms projects you need to your solution.
Add references to the Class Library project to your winforms projects.
There is nothing special about multiple project within a single solution - VS 2010 supports this fully, see http://msdn.microsoft.com/en-us/library/23x5fk78.aspx .
You can also add the same project to multiple solutions. There is no need to have both the server and client output in a single solution.
In other words, if these are the projects you want to use in both server and client:
Project A: CoreClasses
Project B: Entities
Then simply add them to both solutions:
+ Solution 1: Server
+- Project A: CoreClasses
+- Project B: Entities
+- Project C: ServerSpecific -> output
+ Solution 2: Client
+- Project A: CoreClasses
+- Project B: Entities
+- Project D: ClientSpecific -> output
In your trunk, it would look something like:
/trunk/
/trunk/ProjectA/
/trunk/ProjectB/
/trunk/ProjectC/
/trunk/ProjectD/
/trunk/ClientSolution.sln
/trunk/ServerSolution.sln

Sharing code between 2 projects without a dll

How can I have code-sharing between two projects without making a dll?
The issue is: I have a tool that syncs users & groups from LDAP to a database.
Now the tool is a windows service, but testing it as such is very difficult and time consuming.
Which is why I made a console application where I can test the LDAP syncing, and then just copy the respective sourcecode-files over to the service project.
But... keeping the common files in sync is a bit of a problem.
I don't want to make a dll, because this probably creates me a problem with
the 3rd project, a windows installer (for the service) where I have to use ExecutingAssembly path...
Is there a way to share the code without making a separate dll?
Automagic statical linking, so to say ?
How about adding a file as a link.
In Visual Studio right click on your console test app project -> select add existing file -> in the file add dialog navigate to files in your actual windows service project -> select the files you want to share -> and on add button select add as link option.
You can add a file to a project as a link. On the Add Existing Item dialogue the Add button has a drop down on its right. Use this to select "Add as Link":
Put the file as a solution item and add as a link to each project.
How about hand-modify the project files to point to the same source file?
Another option - put both projects in the same folder. Add a class to one, then in the other project add existing class and point to the class just created.
You could:
maintain the shared code in a separate project that produces a DLL and then use a tool such as ILMerge to turn the DLL & EXE into one assembly.
share the source-files between multiple projects, either by tweakiing your project files or doing something funky with your source-tree layout.
All that said, the best approach would be to bite the bullet and store the shared code in a shared assembly (DLL). What happens when you decide to, for example, expose this code via a WCF service? It starts getting more complicated then as you have 3 places that reference the same code files. Don't just think about what makes your life easiest now, think about what'll make your life (and that of anyone else who has to maintain the code) easier in the future as well! =)
Necromancing - As per Visual Studio 2017:
You can create a shared project, and then reference the shared project in another project.
It will use the framework-version and libraries from the project you reference the shared-project from. You can also use the same shared project in multiple projects, provided you get no conflict.
This is basically statical linking on a source-code level.
This also works with HTML&JavaScript-files (specifically, it works with publishing), but with HTML & JS files, you will run into problems while debugging...
It's under "Classical Windows Desktop", but you can also use it for .NET Core etc.
If you want to share functionality, you should use a DLL or similar.
Since what you want to share is the source, what you are essentially sharing is file sharing. So you can do that by making your projects reference external sources or you can have your source control do this for you.
If you are using Visual SourceSafe, you can make a link between two folders. VSS will make sure that they are treated as the same file.
I'm going to describe the setup we use to manage and test our Windows Service projects. While this doesn't answer the question of "sharing code without a DLL" (Unmesh's answer takes care of that), I think the OP probably doesn't realize how easy this is with a DLL. In any case, I'm hoping it will help someone.
Create a solution, LDAPSync. Create three projects in this solution:
LDAPSyncLib
LDAPSyncSvc
LDAPSyncTest
LDAPSyncLib is a DLL project that contains all of your business logic and main functionality.
LDAPSyncSvc is a Windows Service project that contains two classes, a service controller class that inherits from ServiceBase, and an Installer class for your service. This project has a "project reference" to LDAPSyncLib.
LDAPSyncTest is either a GUI application (WinForms, WCF, etc.) or a console application, depending on your needs. This project also has a "project reference" to LDAPSyncLib. Its sole purpose is to provide some interface which allows you to easily make the required calls into your business logic for testing purposes. In Visual Studio, set this as your "StartUp Project".
Now, when you run in debug via Visual Studio you will get a nice little GUI or command window that you can use to manually make test calls. When you install it as a Windows Service, the LDAPSyncSvc project's controller class will take over and handle all of the necessary service requests (start, stop, pause, etc.)
We have around 30 in-house Windows Service projects that we've been continuously managing, developing and testing for over a decade and this workflow has proved invaluable in quickly finding and fixing bugs when they arise. Best of luck with your project and I hope this helps some future Googlers.

Categories

Resources