How to place aspx-files in seperate Web Application Projects in one solution?
We have been building ASP.Net websites for many years. During this time we gathered a lot of knowledge of ASP.Net. We know what to use, a what not. One problem is still, persistently, bugging us. I hope to solve this for once and for all.
We have a fairly large solution with lots of aspx-files. All aspx-files reside in one Web Application Project. This single big WAP needs to be split in multiple smaller projects. The exact reasoning is beside the point, please believe me ;-).
There are a 开发者_运维问答number of ways to accomplish this, but I am still unsure what the best way would be. We use ASP.Net 4.0 and Visual Studio 2010 Premium.
Any advice is greatly appreciated.
This is our current work-around (which we do not like)
- Create a WAP (Runner).
- Create a second WAP (ProjectA)
- Create a third WAP (ProjectB)
- Delete the web.config's in ProjectA and ProjectB
- Create a simple aspx-file in Runner, ProjectA and ProjectB with a hello world message
- Remove ProjectA and ProjectB
- Go to Windows Explorer
- Move the folders ProjectA and ProjectB inside the folder Runner
- Go back to Visual Studio
- Add Existing Project to solution (ProjectA and ProjectB)
- Hit F5
- Navigate to http://localhost:4867/WebForm1.aspx
- Navigate to http://localhost:4867/ProjectA/WebForm1.aspx
- Navigate to http://localhost:4867/ProjectB/WebForm1.aspx
Tada! The above works, but it feels like a hack and it smells awful. Is there a better way?
Here is what Scott Guthrie says on this. I think the second method is a superset of your procedure. In my opinion you are right: This is a hack - but the official one.
I suggest creating a new solution, and creating your required new empty web application projects under it. Then, manually copy your files from their original locations into the proper new folders which were created when you created the empty projects. After all the files are in place, go back to VS. Set Solution Explorer to 'Show All Files'. Select the the files you need in each project, right click, and select 'Include in Project'.
The only wrinkle I can think of is that creating all web applications will mean you have a web.config file in each. If this is what you need, then fine. Otherwise, you create some of the projects as class libraries.
精彩评论