Nick
Nick

Reputation: 978

visual studio opening web browser + debugger in a console app rather than a web project

I have recently changed some projects from IIS ASP NET projects to Console Applications, using a custom web server. In both kinds of project, we ran the project as a console aplication (so we didn't actually use IIS),

However, as a web project, the profiler does not work. So we changed the project to be a console application, which makes the profiler work. Unfortunately, this removed the option to run a web browser and attach the debugger automatically. This appears in visual studio like so:

Console Application:

enter image description here

Web Project:

enter image description here

Is there a way to get this back whilst still being a console application?

I've tried adding this to the .csproj:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
        <WebProjectProperties>
          <UseIIS>False</UseIIS>
          <AutoAssignPort>True</AutoAssignPort>
          <DevelopmentServerPort>52826</DevelopmentServerPort>
          <DevelopmentServerVPath>/</DevelopmentServerVPath>
          <IISUrl>http://localhost:53107/</IISUrl>
          <NTLMAuthentication>False</NTLMAuthentication>
          <UseCustomServer>True</UseCustomServer>
          <CustomServerUrl>
          </CustomServerUrl>
          <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
          <servers defaultServer="SelfHostServer">
            <server name="SelfHostServer" exePath="" cmdArgs="-c http://localhost:52826/" url="http://localhost:52826" workingDir="" />
          </servers>
        </WebProjectProperties>
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>

But this didn't seem to help. The more modern .net core apps seem to be console applications as well, but they somehow can start the browser and attach the debugger. We are using visual studio 2017, but we will happily upgrade to 2019 to fix the problem. The JetBrains Rider IDE also seems to be able to start a web browser and debug on any kind of project as well.

Upvotes: 4

Views: 2740

Answers (1)

Thymine
Thymine

Reputation: 9195

Easy solution (uncertain if will work, let me know):

  • Go into the Properties for the project in VS2017, and go to the Debug tab. Do you have options to Launch browser? (sorry I don't have 2017 installed anywhere currently)
  • Alternatively to launch any custom commands? And have that point to your debugging instance.
  • (negative) Runs the risk of not being cross-functional between teammates or environments

Since you mentioned upgrading to VS2019, I'm going to suggest that as the nicest solution.

Update all the project files to the new format. And all of them should have in the Properties>Debug the option to launch a browser.

Also the reason that it works in DotNetCore is because DotNetCore did away with the notion of running inside of IIS or similar, Kestral is hooked up from a Main entry method just like console applications, allowing less confusion for situations such as yours. And VS2019 should support that arrangement no matter what your target framework is.

Upvotes: 4

Related Questions