在.NET Framework SDK样式的Web项目中启动浏览器

ltqd579y  于 2022-12-30  发布在  .NET
关注(0)|答案(3)|浏览(121)

我们将一些Web项目更改为SDK样式,但如果在Visual Studio中启动项目,则不会启动浏览器。IISExpress命令提示符确实会运行并启动网站,因此手动访问网站时可以正常工作。
当使用SDK风格的项目时,是否可以启动浏览器?(或者是否有解决方案/工具使其成为可能?).我知道对于dotnet核心网站,这确实有效,并且启动了一个新的浏览器示例,也许我们应该只保留.NET Framework Web项目的旧格式。

启动设置.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 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>

信息

  • 可视化工作室2019(16.4.2)
  • .NET框架4.6.1
  • IISExpress启动和运行良好
  • 我可以手动访问网站,但浏览器不会自动打开。
ie3xauqp

ie3xauqp1#

导入System.Diagnostics后,可以在启动文件的底部插入下面的示例。

Process.Start("chrome.exe", "https://google.com");
q9rjltbz

q9rjltbz2#

您可以尝试更改json:

"profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }    
      "applicationUrl": "http://localhost:29750/"
    }
l3zydbqr

l3zydbqr3#

既有要求MS处理此问题的请求https://github.com/dotnet/project-system/issues/2670,也有要求MS处理此问题的第三方软件包https://github.com/CZEMacLeod/MSBuild.SDK.SystemWeb(可通过nuget在https://www.nuget.org/packages/MSBuild.SDK.SystemWeb/4.0.82下载)
我建议既要对MS问题进行投票,也要尝试一下MSBuild.SDK.SystemWeb。

相关问题