4

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.

Nick
  • 920
  • 1
  • 7
  • 21
  • In Properties (within the project in Solution Explorer), you should have a launchSettings.json file, can you include that for your web project in your question please? Upgrading to VS 2019 won't change how it launches. – Kody Aug 13 '19 at 22:15
  • that doesn't seem to exist? This is an old style csproj file if that helps – Nick Aug 15 '19 at 16:19

1 Answers1

4

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.

Thymine
  • 8,775
  • 2
  • 35
  • 47
  • awesome i will try some of this out! – Nick Aug 15 '19 at 13:31
  • it seems even in VS 2019 you need to use the new cs proj files to get this working? – Nick Aug 15 '19 at 16:21
  • Yeah that would be my understanding. From what I've done, its often easiest to just create a new csproj from scratch, then copy the files into it (since you only need to copy the directories, and they should get added when you load the csproj automatically) Otherwise there is https://github.com/hvanbakel/CsprojToVs2017 but I've had it give weird results – Thymine Aug 15 '19 at 18:42
  • god c# configuration is such a nightmare – Nick Aug 16 '19 at 09:13
  • unfortunately, the build server can't build the project because it doesn't have the right version of nuget or doesn't have a target for '.NETFramework,Version=v4.7.2/win7-x64'. Ensure that restore has run and that you have included 'net472' in the TargetFrameworks for your project. You may also need to include 'win7-x64' in your project's RuntimeIdentifiers. – Nick Aug 16 '19 at 09:24
  • intellisense also seems to have broken for conditional compilation symbols in the new csproj format? – Nick Aug 16 '19 at 09:28
  • okay i've added the new project format, used VS 2019, and there is still no option to open with a web browser? – Nick Aug 16 '19 at 09:50