How to locally run .Net Core 2.0 app in VS Code the same way Visual Studio does with SSL - asp.net-core

So, we have a web app we've migrated to .net core, and while it runs fine in Visual Studio 2017, because Visual Studio uses its "launchSettings.json" file to configure how IIS Express will work/launch - I, for the life of me, cannot figure out how to get VS Code to run the project. The problem is, we use HTTPS only and have always just let IIS Express used the self-signed locahost cert to allow this, so when debugging the site locally, we'd always use https://localhost:44300. As stated, this worked fine when entering this url in the launchSerttings.json file for Visual Studio, but VS Code does not use this, and the only answers I can find on this always refer to having to use the Kestrel Server's .Listen() method and used a self-signed cert and password to allow the use of an HTTPS port. 1) this seems just silly that I'd have to add this "test" code to run it locally, because I don't need it when we deploy to Azure, as Azure manages the certs and url for us. 2) Visual Studio 2017 does not need any specification on Kestrel to make this all work. So, I have hard time believing there isn't some extension, or process to achieve the same thing in Visual Studio Code that Visual Studio is doing under the hood to allow IIS Express to communicate with the .Net Core Kestrel Server.
Combing through the all the documentation suggests that the ASPNetCoreModule is what handles this communication for IIS and Kestrel, so, I would hope/guess there has to be some way to configure the web.config file's tag to include something that would make this work.
I've previously used and tried other IIS execution extensions in VS Code, but those focus on elements in the project's web.config to boot IIS which are no longer present in the web.config due to it being a .Net Core app. I had been successfully running the web app with the IIS Express Executor extension before migrating to .Net Core when the web app was a .NET Framework 4.5.2 app
So, the end goal is that I need to be able to go to https://localhost:44300 in the browser, and have our site work, but I don't want to have to add any sort of test-cert into the Kestrel config in the Program.cs or Startup.cs files. If there's no way to do this, then that will be really disappointing considering Visual Studio makes this seem like it should be very simple.
Thanks for the help.

Was able to get this to work using the following steps.
1) Install IIS Express executer in VS Code or any other similiar extension that wraps around dotnet commands
2) Download Process Explorer from https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer
3) Launch Visual Studio IIS Express as you would normally
4) Open Process Explorer (may need to launch as Admin) and locate iisexpress.exe -> VSIISExeLauncher.exe
5) Right click VSIISExeLauncher.exe and click properties then locate the "Environment" tab. Inside the environment tab you will see 2 variables: LAUNCHER_PATH and LAUNCHER_ARGS. Copy both of these variables and values.
6) Next locate the configuration file for the extension you installed in VS code (mine is launch.json inside the .vscode folder in your project root directory). It will likely have an "environment" or "env" section for adding environment variables to the launch arguments. Add the two arguments copied from step 5. These vary from person to person so the value of the arguments will be unique to your machine.
7) Launch IIS-Express from vs code. My particular command for this is "IIS-EE: Start IIS Express Server" but will vary based on the extension you installed. You can hit F1 to launch commands.

Visual Studio itself uses too many tricks under the hood to make you believe it is simple. However, it is not.
I documented all necessary details in a blog post,
https://blog.lextudio.com/how-visual-studio-launches-iis-express-to-debug-asp-net-core-apps-d7fd3677e3c3
And if you follow the steps manually, you should be able to launch IIS Express the same way VS does, and then use that in Visual Studio Code. I know there is some VSCode extensions trying to integrate with IIS and IIS Express, but I do hope those authors spend more time learning such integration and improve their extensions to fully support the scenarios.

Related

Running winforms client, does not start iisexpress with the referenced wcf service - under Windows 10. Ideas?

I have a vs solution with 2 projects - WinForms client, and WCF Service.
Since visual studio 2013 to 2019 (I was under Windows 7), every time when I ran in debug the WinForm client, VS automatically was starting the IISExpress in background(I want that!), and my calls from the client were successful, stopping on breakpoints inside the WCF service easy.
Last week, I got new box with Windows 10. Now when I start the client, there is no iisexpress.
The source code is the same and not changed - my co-workers are under Windows 7 and this works for them - same code - we use git as version control.
The only time I see iisexpress is if I do "Update Service Reference" or I make the WCF startup project and run it.
Can you help me identify why this functionality stopped working? Ideas for a fix?
Windows 10, Visual Studio 2019 Enterprise, .NET 4.6
EDIT: I do not have problem running the webservice in IISExpress, when i specifically run it - it works, also on solution level if I set 2 startup projects, all will work. The main issue is that with Single Startup project - thw WinForms client, Visual Studio will not bring up the IISExpress instance. It is only development time issue, and this works for my co-workers.
The solution is in the VS generated (regenerated if missing) user file in the WCF project
.csproj.user
there is property
<AlwaysStartWebServerOnDebug>True</AlwaysStartWebServerOnDebug>
It must be True, but now it is defaulted to False.
The *.user files do not go to version control, and if they are missing VS regenerates them, hence my coworkers had it, and my freshly cloned repo did not.
I'm pretty sure I never touched this file or did any configs like that on the WCF project, my suspicion is that MS decided to start defaulting to False in some version or patch.
WARNING! After changing the option, close/open the entire solution or restart VS.
Disclaimer: I found this solution in the build in VS report problem button leading to a portal with reported problems and solutions. I do not see how to copy link or anything from that Feedback tool, but this is the guy that deserves the credit: 佐々木隆幸
It seems that you want to debug the WinForms application separately regardless of the WCF application. we could set up the project dependencies in the property page of the VS solution.
Then open the SVC file, press F5 to launch the WCF application so that we can add service reference in WinForms application.
Please ensure the below configuration in the property page of the WCF application project.
Besides, if there is something wrong with the IISExpress, we could opt to repair the IISExpress in the below dialog.
On my side, it works like a charm.
Feel free to let me know if the problem still exists.

Web server for ASP.NET 5 that works without debugging active

sorry if this is a stupid question but I don't get it.
So I've created an ASP.NET 5 page using Visual Studio 2015 and DNX.
Out of the box I have these two dependencies in my project.json:
"Microsoft.AspNet.Server.IIS": "1.0.0-beta4",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta4"
Under "commands" in project.json I have the following:
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"
In the project properties I can change profiles between "IIS Express" and "web" as deployment options. Both are working fine, when I start debug it starts the web server (either IIS Express or the WebListener) and the site is working. If I stop debugging the server stops. The WebListener opens a "dnx.exe" in a command prompt.
This pluggable server layer is really nice, I get the point. But how do I, as a developer setup an easy server where I can make a change to my site and quickly see the changes?
I can of course install IIS and create a site that is pointing to my wwwroot but is that my only option in the ASP.NET world? Can I have the WebListener "started in the background" (without showing me a command prompt with dnx.exe)? I can also start a node server but yet again - it's great that i can but why do I have to when I have the full ASP.NET toolbelt?
ASP.NET 5 has dynamic compilation but I'm not sure how to even test it since my web server is only started when I'm in debug mode.
I know that this is a pre-release but any help would be greatly appreciated.
But how do I, as a developer setup an easy server where I can make a
change to my site and quickly see the changes.
Regardless of the server used, you can use dynamic compilation by Starting the project without debugging (Shift + F5).
Due to architectural reasons, dynamic compilation does not work when starting with debugging (F5) in Visual Studio. This is due the fact that the difference between Shift + F5 and F5 is that in the latter, VS attaches the debugger to the process.
Will this every be supported in the future? That is unclear but right now because VS isn't "smart" enough to handle detaching from process, waiting for dnx to dynamically recompile, and then reattaching to the process. However until now it never had a reason to support such a scenario, so it is unclear if it is just a "it doesn't know how to do it yet" or a "it is impossible to do."
I can of course install IIS and create a site that is pointing to my
wwwroot but is that my only option in the ASP.NET world?
No. You can use any webserver which supports Microsoft.AspNet.Hosting. Today your choices are limited to IIS, IIS Express, and the two experimental servers you linked to but the goal is to enable third parties to develop alternatives by providing an interface that can be programmed against (Microsoft.AspNet.Hosting).
ASP.NET 5 has dynamic compilation but I'm not sure how to even test it
since my web server is only started when I'm in debug mode.
If the web application is running then the server is started. No webserver = no ASP.NET application. I assume by "debug mode" you mean "Start with Debug (F5)". If so then "Start without Debug (Shift + F5)" to fix the problem you're experiencing.
Here is an excercise:
Close Visual Studio (not a requirement but useful to show none of this is VS specific).
Start the web server. The easiest way would be dnx . web run from command line in the project root folder. You could however start IIS Express (should already be configured) or even configure the IIS and start it.
Verify the web server and web application is running by opening it in a browser.
Using notepad or some other text editor, edit a file in the project that would have a visible change or just force an error "throw new NullReferenceException()".
Save the file.
Refresh the browser.
The web application will reflect the change. You may notice a slight delay if you refresh quickly. That is the dynamic compilation to memory occurring.

Deploy MVC 6 app in IIS

I'm using Visual Studio Express 2015RC and I created a simple MVC 6 application, but when I try to publish it I don't see the option to deploy it to IIS, I see the options Microsoft Azure Web App, Import and File System, I tried the File System but It looks like it is more for creating stand alone applications to be launched from a console, now, when debugging I can select IIS Express or the web command, there is no IIS option, so the question is, how can I deploy the MVC6 web application I created to IIS?
File System publish is actually exactly what you want; All DNX applications are stand-alone, whether for ASP.NET 5 or a console app.
When you publish to the File System, you get a few folders; the wwwroot (assuming you kept the default in your project.json) folder is where IIS should point. The web.config in that folder is generated for you automatically assuming you keep everything else where it is.
For what it's worth, the official documentation will probably be here, once it's written. Also, on Stack Overflow, ASP.NET 5 project hosting on IIS probably has some useful information, though it looks like it's a bit out of date at the moment.

IIS Express Error http 404.17 – not found running a WCF service

I just created a WCF Service Application in VS2013 with framework 3.5. for exposing some methods I have in a class library project.
Everything went fine but when I tried to see if the service runs, it doesn't. Instead I got the next error.
HTTP Error 404.17 - Not Found The requested content appears to be
script and will not be served by the static file handler.
Most likely causes: The request matched a wildcard mime map. The
request is mapped to the static file handler. If there were different
pre-conditions, the request will map to a different handler.
Things you can try: If you want to serve this content as a static
file, add an explicit MIME map.
I have dealt with it on IIS, but now in IIS Expres I'm kinda lost.
I don't have IIS installed on this machine since I'm using a remote one, but I need to debug some things and I'm stuck. Thanks for any help.
I also did run servicesmodelreg -i with visual command prompt, but error persists.
UPDATE
It may be usefull to clarfy it only happens in IIS Express so it is impacting development. I have VS2013 updated to the latest patch running on Win 8.1 64bit
Try to run "C:\Program Files\IIS Express>Wscript.exe WCF35Setup.js install" that is a script for enabling WCF 3.5 service on IIS Express.
Reference : http://www.iis.net/learn/extensions/introduction-to-iis-express/iis-75-express-readme
Seems WCF mapping are not registered with IIS.
To solve the above error:
Navigate to "
%SYSTEMROOT%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation
" at the Visual Studio command prompt.
Execute "servicemodelreg -i" to install the mappings manually.
For more details refer :ServiceModel Registration Tool (ServiceModelReg.exe) on MSDN.
-
Alternatively,
enable HTTP Activation for WCF services in Windows features.
Click the Start button, and then click Control Panel.
Click Programs, and then click Programs and Features.
On the Tasks menu, click Turn Windows features on or off.
Select the WCF Non-Http Activation Components box and save the
setting.
Source :
http://msdn.microsoft.com/en-us/library/ms732012(v=vs.110).aspx
After trying all the recommended solutions suggested here up to this point:
servicemodelreg -i
Wscript.exe WCF35Setup.js install
enable HTTP Activation
And a few others suggested elsewhere:
Run Visual Studio as Admin
Use "Local IIS" instead of IIS Express
I finally determined what my issue was. The WCF code was targeting .NET framework 3.0, and I had not enabled IIS support for 3.0/3.5!
The solution was simple. Enable ".NET Extensibilty 3.5 and ASP.NET 3.5".

Can adding a solution to TFS server cause WCF to break?

I am running on SP1 beta of 2010... it may or may not related to the beta. But, in general, can adding a project to the codeplex TFS server somehow make WCF break when also inside an Azure project?
Seems to be the pattern for me. Immediately upon launch I get a ServicePoint exception. If I remove the app from source control everything works fine.
My project consists of
Azure WCF hello world application
VS2010 SP1 beta
Adding codeplex TFS reference causes exception
Is it a CommunicationFaultedException? If it is, it is a bug when working with Azure 1.3 SDK projects that are checked into TFS. Make sure you have the Web.config file checked out (writeable).
If not, can you give any other information on on the ServicePoint execption?