Debugging multiple ASPNET Core applications simultaneously in Visual Studio - visual-studio

Setup
We have a VS 2017 solution with 2 ASPNET Core 2.0 projects:
Project 1: WebUi - an UI project based on Vue with Typescript that contains the frontend of the application
Project 2: WebApi - an WebAPI project that contains all the api implementation
The productive deployment under IIS looks like this:
The Web Physical Path points to an empty folder. The WebApi points to the folder where the WebApi VS project is published. The WebUi points to the folder where the WebUi VS project is published. This works fine: the WebApi is accessible under /webapi and the WebUi is accessible under /webui. This setup also means that we don't need to handle CORS requests, since both projects run under the same domain.
What we are trying to achieve
Now we are trying to define a setup in VS 2017 that will allow easy debugging of both projects at the same time. What we have got so far is to publish the projects in debug mode and then attach to the hosting executables. This works fine. The problem is that for each change in the code another publish is needed in order to debug the new code. This takes too much time.
What would be much better is to just hit F5 in VS which would start both applications under the same host (like the IIS setup) in debug mode and be able to debug both projects at the same time. One project at a time works, but not both.
We have tried Setting the AppUrl of both projects in debug properties to the same url but with a different path:
Project WebUi:
Project WebApi:
But unfortunately this did not work.
How can we set up our project such that there is an easy solution to debug both projects at the same time?

I don't believe this is possible. From my experience you can only attach the debugger to a single project under a solution. Personally i would merge the two projects, with the API section being in an API Area. Another route is to move the two projects into their own solutions then you will have to open 2 visual studio instances to run the site.
Setting up an Api area inside the Ui Project
Startup.cs, Configure method
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areaRoute",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
Create an folder structure Areas > Api > Controller. Then put all your API controllers in the folder. Then add Area and Route Attributes to all Api controllers
[Area("WebApi")]
[Route("[area]/[Controller]")]
With this set up the Ui project will reside on / and the api will reside in /WebApi. The whole solution will have one project, one IIS site, and VS will be able to debug everything at the same time. If you want the Ui to reside on /WebUi, either update your primary routemap or create another folder in Areas.

If you want to debug the deployment projects, I think the only option is to attach the debugger twice from VS to each app.
We usually develop project by Running project under IIS by changing Project properties->Web->Servers->Local IIS->Create Virtual Directory for the two projects, then it will run under IIS when debugging.
To run both projects, you could follow Solution properties->Startup Project->Multiple startup projects-> Set Start Action for them->F5, VS will run both projects.
So you could follow above steps to re-publish your projects, then you will be able to debug for both projects, or, you could only use for development and test, you could publish them if there is no problem.

Related

WebDeployment is not

I am trying to deploy an web application that was created on VB with the .NET Framework 2.0 using the TFS 2017 continuous deploy. It doesn’t have a solution file inside like vbproj or csproj, so I needed to avoid all the suggestions to include extra information on the vbproj.In order to run the MSBuild even locally I need to change in my .sln this tag, so all my compiled code is also there
Debug.AspNetCompiler.TargetPath = "....\PrecompiledWeb\ARB\Debug\"
Unfortunately, I can’t deploy the application using the TFS. So far I tried to deploy it through my Visual Studio project, and is working fine with every option: I tried MSDeploy, Web Deploy Package, and FileSystem, and is working fine from the Visual Studio Publish Option
With that, even my transformation take place.
Now lets say I go to my TFS and I put this parameters on the MSBuild
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsASingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="\\MyServer\Content"
My files are compiled but never stored in my Content folder. No one of them!!! I can’t figure out what is going on here.
From your screenshot, you are using a Web Site project, not a Web Application project. The output structure of a Web Site project in TFS is different from build in VS (you can see a PrecompiledWeb folder in your build source directory on build agent server). Instead of using MSBuild argument, you can consider add tasks below to copy the files you want to publish:
We strongly suggest you switch from Web Site projects to Web Application projects to avoid these issues.

WCF IIS configuration and Visual Studio 2010 debug configuration

I am trying to set up my WCF service (.svc) to work in Visual Studio 2010 (pressing F5 to debug), but also to have multiple configurations for each environments (DEV, QA, UAT & Prod). When I originally built the WCF it was used purely in Visual Studio 2010 using .Net version 4 and debugging the service was easy enough by adding a WinForm application to pass in the values needed. When it was time to test the service on a server, I used the Publish feature to put the files on the DEV server and noticed that since it was using IIS that a web.config was created in the base directory.
So now that we are moving on to QA and UAT I need to make sure we have the configuration files for each environment as the Uri's change as well as various other values. Now after searching for a few days on Google, I have tried to use the XDT Transformations, but without having a third party add-in like SlowCheetah, this does not seem to work as it is only built for Web Applications. I have also tried to set up a post-build event to copy different configs:
copy "$(ProjectDir)Config\web.$(ConfigurationName).config" "$(ProjectDir)web.config" /Y
The copy process is set in the Build Events --> Post-build event command line textbox, however this does not seem to work when I use the publish method. I am ok with using multiple config files and copying them, I just have not had success with this.
The XDT makes the most sense to me and would be my preference if I could get it working. The main issue I am having is that it needs to work in Visual Studio, but also to work via IIS on the servers without having to go through a bunch of steps per environment. This is a company rule that I have to follow as well as not having a third party plug-in/add-in.
Is it possible to run the service in IIS and create a servicehost via code? I don't think it is as I believe the MSDN docs say that IIS creates it for you no matter what. Part of my reason wanting to do different configs is so that the page the user gets when they view the .svc file in the browser has the correct Uri in it not the machine name version.
TIA
EDIT: Setting up a dev web.config and including it in the project and then setting it to Build Action: Content fixes the copy method, so technically I have it working as long as I have completely different web.config files for each environment and an app.config for debugging (F5 in Visual Studio).

JuiceUI - sharing across projects

Is there a known way to configure JuiceUI to exist in one Visual Studio Web Application project and reference it from another Web application? We want a centralized location for all of our Web Application to use it instead of having to install the JUiceUI.dll and Scripts folder in every project.
Thanks

"Calls to the web service will fail unless the Silverlight project is hosted in and launched from the same web project"

I have Downloaded demo project from here
I tried to run Silverlight project SkiResult.ThinClient from the “Solution Explorer” I have configured the database nicely as SkiResult.FullClient a WPF Project works fine and display data.
But whenever I have tried to run Silverlight project in my Solution Explorer it shows me following error message.
I have googled so much I have also found one solution that set xyz.WEB project as a Start Up Project but as u can see from below screenshot of my Solution Explorer there is no xyz.WEB project in solution.
Thank you so much.....
Try setting the SkiResult.DataService project to be the startup project. This looks very much a web project created to host a Silverlight application because:
it has a Web.config file (so it is clearly a web project)
it has a Silverlight.js file (some utility JavaScript used with Silverlight),
it has some autogenerated test pages,
it has a ClientBin folder, which is typically where the compiled Silverlight application will be copied to.
When you create a Silverlight project, Visual Studio offers to create a web application project to host the Silverlight application for you. (You don't have to create a web application - VS can generate a test webpage during the build process and use that instead.) If your Silverlight project is called Xyz, then this web application will be called Xyz.Web. However, with the solution you're dealing with above, it seems this project has been renamed from the default.

Web Application within a Web Site in Visual Studio?

Visual Studio allows you to make "Web Sites" and "Web Applications", but, inside a project, can you have one within the other?
Say I have my website "www.mysite.com" and I have an application called "BudgetCalculator". One the production server, this is supposed to be located at:
www.mysite.com/BudgetCalculator
And the BudgetCalculator app contains links back to other parts of the website, like "/page1" and "/page2".
However in Visual Studio, when they're listed as two different projects, they're on the same level. When I fire up the debugger for the BudgetCalculator app, those links aren't going to point back to the main website, like they should.
Is there a way around this?
One solution would be to stop using the built-in .NET Web Server.
Use IIS, create one site, and make your Web App a Virtual Directory inside of the Web Site.
A project cannot host/contain another project in Visual Studio.
You can however create a project that sites in the directory of another higher level project when you create it, however they may not be directly linked, so you couldn't debug them both at the same time.

Resources