Reputation: 1574
We changed a few web projects to SDK style, however it won't launch the browser if we launch the project in Visual Studio. The IISExpress command prompt does run and starts the website, so when accessing the website manually it works.
Is it possible to launch the browser when using an SDK style project? (Or is there a workaround / tool to make it possible?). I know that with dotnet core websites this does work and a new browser instance is launched, maybe then we should just keep the old format for .NET framework web projects.
launchSettings.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:29750/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "Executable",
"executablePath": "C:\\Program Files\\IIS Express\\iisexpress.exe",
"commandLineArgs": "/path:\"$(SolutionDir)$(ProjectName)\" /port:29750",
"launchBrowser": true,
"launchUrl": "/"
}
}
}
Project, removed scripts and few views
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="Current">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<AssemblyName>Web</AssemblyName>
<OutputType>Library</OutputType>
<OutputPath>bin\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Antlr" Version="3.5.0.2" />
<PackageReference Include="Castle.Windsor" Version="3.4.0" />
<PackageReference Include="Castle.Windsor.Mvc" Version="1.3.0" />
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.7" />
<PackageReference Include="Microsoft.AspNet.Web.Optimization" Version="1.1.3" />
<PackageReference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" Version="2.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Owino" Version="1.0.2" />
<PackageReference Include="SignalR.Castle.Windsor" Version="1.0.1" />
<PackageReference Include="Westwind.Globalization" Version="3.0.5" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<Compile Remove="obj\**" />
<EmbeddedResource Remove="obj\**" />
<EntityDeploy Remove="obj\**" />
<None Remove="node_modules\**" />
<None Remove="fonts\**" />
<None Remove="obj\**" />
<None Remove="Scripts\dist\**" />
<None Remove="package-lock.json" />
<None Include=".babelrc" />
<None Include=".eslintignore" />
<None Include="package.json" />
<None Include="Views\Protocol\Index.cshtml" />
<None Include="Views\Settings\Index.cshtml" />
<None Include="Views\Shared\_Root.cshtml" />
<None Include="Views\Shared\_Shared.cshtml" />
</ItemGroup>
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Info
Upvotes: 5
Views: 1919
Reputation: 13571
There is both a request for MS to handle this, https://github.com/dotnet/project-system/issues/2670, and a 3rd party package that does so now https://github.com/CZEMacLeod/MSBuild.SDK.SystemWeb (can be downloaded via nuget at https://www.nuget.org/packages/MSBuild.SDK.SystemWeb/4.0.82)
I would suggest both voting on the MS issue and giving MSBuild.SDK.SystemWeb a try.
Upvotes: 0
Reputation: 48
You can insert the below sample at the bottom of your startup after you import System.Diagnostics.
Process.Start("chrome.exe", "https://google.com");
Upvotes: 1
Reputation: 6528
Can you try changing the json:
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
"applicationUrl": "http://localhost:29750/"
}
Upvotes: 2