2016-07-16 88 views
5

我有一個工作web.config中,如下圖所示:ASP.net核心1.0 web.config文件被覆蓋造成CGI例外

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <!-- 
    Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380 
    --> 
    <system.webServer> 
    <handlers> 
     <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" /> 
    </handlers> 
    <aspNetCore processPath="dotnet" arguments=".\Example.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" forwardWindowsAuthToken="false" /> 
    </system.webServer> 
</configuration> 

但不知何故,Visual Studio是更新我的web.config:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <!-- 
    Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380 
    --> 
    <system.webServer> 
    <handlers> 
     <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" /> 
    </handlers> 
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" forwardWindowsAuthToken="false" /> 
    </system.webServer> 
</configuration> 

這可以通過發佈菜單在Visual Studio中工作(並且一旦部署到一個天藍色的web應用程序就可以工作)。如果我使用dotnet CLI(如dotnet publish),它不起作用,因爲它使用變量:%LAUNCHER_PATH%和%LAUNCHER_ARGS%保留web.config,而不是我想要的:dotnet和。\ Example.dll。

注意:當使用dotnet恢復和通過命令行構建dotnet時,我的構建服務器不污染web.config。也不使用MSBuild來建立我的SLN。我在本地以及構建服務器上安裝了visual studio 2015,並驗證了我的命令行版本與「dotnet」cli匹配。

如何在每次提交之前通過回滾web.config來對抗Visual Studio?我顯然做錯了,應該是一個簡單的配置修復?

更新:

Startup.cs

public Startup(IHostingEnvironment env) 
{ 
    var builder = new ConfigurationBuilder() 
     .SetBasePath(env.ContentRootPath) 
     .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) 
     .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) 
     .AddEnvironmentVariables(); 
    Configuration = builder.Build(); 
} 

Appsettings.json

{ 
    "Logging": { 
    "IncludeScopes": false, 
    "LogLevel": { 
     "Default": "Debug", 
     "System": "Information", 
     "Microsoft": "Information" 
    } 
    } 
} 

的Program.cs

public static void Main(string[] args) 
{ 
    var host = new WebHostBuilder() 
     .UseKestrel() 
     .UseContentRoot(Directory.GetCurrentDirectory()) 
     .UseIISIntegration() 
     .UseStartup<Startup>() 
     .Build(); 

    host.Run(); 
} 

Project.json

{ 
    "version": "1.0.0-*", 
    "compilationOptions": { 
    "emitEntryPoint": true, 

    "exclude": [ 
     "wwwroot", 
     "typings", 
     "node_modules" 
    ], 
    "publishExclude": [ 
     "**.user", 
     "**.vspscc" 
    ] 
    }, 

    "dependencies": { 
    "Microsoft.NETCore.App": { 
     "version": "1.0.0", 
     "type": "platform" 
    } 
    }, 

    "tools": { 
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": { 
     "version": "1.0.0-preview2-final", 
     "imports": "portable-net45+win8+netstandard1.6" 
    }, 

    "Microsoft.AspNetCore.Razor.Tools": { 
     "version": "1.0.0-preview2-final", 
     "imports": "portable-net45+win8+netstandard1.6" 
    } 
    }, 

    "frameworks": { 
    "netcoreapp1.0": { 
     "imports": [ 
     "netstandard1.4", 
     "dnxcore50" 
     ], 
     "dependencies": { 
     "Microsoft.AspNetCore.Diagnostics": "1.0.0", 
     "Microsoft.AspNetCore.Mvc": "1.0.0", 
     "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", 
     "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", 
     "Microsoft.AspNetCore.StaticFiles": "1.0.0", 
     "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", 
     "Microsoft.Extensions.Configuration.Json": "1.0.0", 
     "Microsoft.Extensions.Logging": "1.0.0", 
     "Microsoft.Extensions.Logging.Console": "1.0.0", 
     "Microsoft.Extensions.Logging.Debug": "1.0.0", 
     "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0", 
     "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0", 
     "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0", 
     "Microsoft.AspNetCore.Hosting": "1.0.0", 
     "System.ServiceModel.Primitives": "4.1.0", 
     "System.ServiceModel.Http": "4.1.0", 
     "System.Private.ServiceModel": "4.1.0", 
     "Presentation.Common": "*", 
     "System.Runtime": "4.1.0", 
     "System.Runtime.Numerics": "4.0.1", 
     "SharedContract": "*" 
     } 
    } 
    }, 

    "runtimes": { 
    "win10-x64": {}, 
    "win10-x86": {}, 
    "win8-x64": {}, 
    "win8-x86": {} 
    }, 

    "buildOptions": { 
    "emitEntryPoint": true, 
    "preserveCompilationContext": true 
    }, 

    "publishOptions": { 
    "include": [ 
     "wwwroot", 
     "Views", 
     "appsettings.json", 
     "web.config" 
    ] 
    }, 

    "scripts": { 
    "prepublish": [ "npm install", "gulp rebuild", "gulp min" ], 
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 
    }, 

    "devDependencies": { 
    "gulp": "^3.9.1", 
    "gulp-clean": "^0.3.2", 
    "gulp-concat": "^2.6.0", 
    "gulp-less": "3.0.2", 
    "gulp-tsc": "^1.1.5", 
    "gulp-typescript": "^2.13.1", 
    "lite-server": "^2.2.0", 
    "path": "^0.12.7", 
    "rimraf": "2.3.2", 
    "typescript": "^1.8.10", 
    "typings": "^0.8.1" 
    } 
} 
+1

我已經知道它發生了,當我點擊在Visual Studio中運行以在本地查看網站時。仍然不知道如何解決這個問題呢。 – Dessus

回答

0

更好地在json文件(如appsettings.json)中遷移您的配置設置,然後在startup.cs中使用configurationbuilder將這些文件設置爲配置源。

+0

我不是如何做到這一點。你能詳細說明嗎?我很可能有一些來自RC2的設置文件,但我確實遵循了許多指南,並且與乾淨的1.0項目進行了比較。 – Dessus

+0

我知道這是我試圖做的,我只是不知道如何。我想我可以以某種方式在某處設置.json文件中這些變量的值。 – Dessus

0

Publishing to IIS

發佈 - IIS工具可以被添加到任何.NET核心應用和 將通過創建或修改 web.config文件配置ASP.NET核心模塊。該工具在發佈dotnet 發佈命令或使用Visual Studio發佈後運行,並將爲您配置 processPath和參數。

從project.json中的發佈後腳本中刪除dotnet publish-iis將停止自動更新。

+0

我的project.json中沒有發佈後的腳本,但這仍然發生 –