在为 IIS 配置后加载我的 ASP.NET 应用程序时发生错误

An error occurs while loading my ASP.NET application after it is configured for IIS

我将我的 ASP.NET Web 应用程序更改为使用本地 IIS,而不是 IIS Express。现在重新打开解决方案后,加载应用程序时出现以下错误:

error : Project 'Atlas2' could not be opened because the Visual C# 2015 compiler could not be created. 'Atlas2' is already part of the workspace.

error : Project 'Atlas2' could not be opened because the Visual C# 2015 compiler could not be created. An item with the same key has already been added.

有人可以帮我重新加载项目吗? 如果有帮助,我正在使用 Visual Studio Team Services(以前是 TFS Online)。

这种情况经常发生在IIS中没有设置身份验证或者IIS中没有设置网站(或虚拟目录)的情况下。要解决此问题,请打开 IIS 管理器。

  1. 确保项目存在网站或虚拟目录,并指向包含项目 bin 文件夹的文件夹。
  2. 打开身份验证并启用匿名身份验证。
  3. 在 select 编辑匿名身份验证时单击“编辑”。
  4. Select 特定用户,输入您的 Windows 凭据 (domain\username)。
  5. 打开 .NET 授权规则。
  6. 确保只有 Allow/All 个用户存在。
  7. 转到应用程序池->高级设置。
  8. Select 身份并输入您的 Windows 凭据 (domain\username)。

这应该会打开网站,以便 Visual Studio 可以加载您的项目。如果没有,请转到您站点的高级设置和 select 物理路径凭据。确保设置为传递身份验证。

我解决了我的问题。我卸载了项目并编辑了 .csproj 文件。我做了以下更改:

  • <UseIISExpress>false</UseIISExpress> 为真
  • 删除<UseIIS>True</UseIIS>
  • 删除<IISUrl>http://localhost/MyWebApp</IISUrl>

然后我重新加载了项目。有效。实际上它回滚到使用 IIS Express。

同样的问题发生在我的系统上,在管理员模式下被 运行 Visual Studio 解决了。问题是 IIS 具有与 ASP.NET 项目相同的主机+端口名称,并且没有管理员权限 Visual Studio 无法添加网站。

我遇到了这个错误。

我正在使用 IIS-Express。我有 VS2015.

在处理 .csproj 文件之后....我能够让它工作。

将我当前的文件与 TFS 源代码管理中的文件进行比较后,唯一的区别是这一行。

以前,这条线不存在。在我的 "working"(弄乱它之后)文件中,我有

<UseGlobalApplicationHostFile />

同样,在导致错误的 csproj 中,我没有魔法线,但在工作的 csproj 中,我有它。

在上下文中,下面是上面的行。只使用下面的面包屑,不要 copy/paste 全部。魔术线是从底部算起3。

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>
    </ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}</ProjectGuid>
    <ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>MyRootNamespace</RootNamespace>
    <AssemblyName>MyAssemblyName</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <MvcBuildViews>false</MvcBuildViews>
    <UseIISExpress>true</UseIISExpress>
    <IISExpressSSLPort />
    <IISExpressAnonymousAuthentication>enabled</IISExpressAnonymousAuthentication>
    <IISExpressWindowsAuthentication>enabled</IISExpressWindowsAuthentication>
    <IISExpressUseClassicPipelineMode>false</IISExpressUseClassicPipelineMode>
    <SccProjectName>SAK</SccProjectName>
    <SccLocalPath>SAK</SccLocalPath>
    <SccAuxPath>SAK</SccAuxPath>
    <SccProvider>SAK</SccProvider>
    <UseGlobalApplicationHostFile />
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

我在 VS 2015 中遇到了类似的错误。

"could not be opened because the visual c# 2015 compiler could not be created." "with the same key has already been added"

我能够通过在 Visual Studio 2013 年打开解决方案解决该问题,清理解决方案,关闭 visual studio,然后在 Visual Studio 2015 年打开相同的解决方案。

我还注意到,在完成这一系列事件之后,最初出现此错误的项目的 csproj 文件更新了其 ProjectExtensions 元素并设置 <UseIIS>False</UseIIS>

下图显示了发生错误时和解决方法后 csproj 之间的差异。

请记住,在我使用此解决方法之前,我尝试手动更新该元素并将其设置为 false,但这没有用。

使用 Visual Studio 2015 从 IIS Express 切换到完整 IIS 后出现此错误。 当我 运行 Visual Studio 作为管理员时,我能够加载项目。

当我将我的 WCF REST 服务从 IISExpress 移动到本地主机时,我遇到了同样的问题。因此,我所做的是在记事本中打开 .csproj 文件并查找 UseIISExpress,将其值从 false 更改为 True。 然后以管理员身份打开VS2015,成功了。好消息是,当我 运行 项目时,它仍然 运行ning 在我的本地主机上,而不是 IISExpress。

问题是该应用程序已配置为使用本地 IIS 而不是 Express,它们可能是您无法加载该应用程序的两个问题。

问题 1.您的本地系统中没有安装 IIS,在这种情况下您必须安装 IIS 或必须打开 .csproj 文件并进行更改:

  <UseIISExpress>false</UseIISExpress> to true
  Remove <UseIIS>True</UseIIS>
  Remove <IISUrl>http://localhost</IISUrl>

问题 2. Visual studio 无法访问 IIS,在这种情况下只需在管理员模式下打开 Visual studio。

我遇到了完全相同的错误,这就是解决我的问题的方法。在您的解决方案的根目录中,您应该看到一个 .vs/config/applicationhost.config。在此文件夹中删除有问题的站点。我的看起来像这样:

        <site name="FrontEnd.Web" id="2">
            <application path="/" applicationPool="Clr4IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="C:\xxxxx\xxxxx\xxxxx\FrontEnd.Web" />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation="*:3391:localhost" />
            </bindings>
        </site>

我删除了此应用程序的整个站点标签,保存并右键单击我的解决方案 > 添加 > 现有项目并将项目重新添加到解决方案。

我遇到了类似的问题,但 none 提到的解决方案对我有用。

但是,我是从 visual studio 最近的解决方案列表中打开我的解决方案。但是当我通过双击从资源管理器中打开解决方案文件时,项目正确加载。

我在 Visual Studio 2017 的升级中遇到了这个问题。它已经修复,现在可以在更新版本中使用。

您可以通过产品内通知或从 https://www.visualstudio.com

下载最新更新

参考: Project could not be opened because the Visual C# 2017 compiler could not be created

我创建了一个新的 Sln 文件。


关闭解决方案。

打开主工程的工程文件。将有问题的项目添加回新的 Sln 文件。

将 Sln 文件保存在旧的错误文件之上。