2017-02-14 56 views
2

我的ASP.NET MVC項目有三個發佈配置文件。關於發佈配置文件名稱的ASP.NET web.config轉換

enter image description here

我需要添加轉化爲他們所有。對於這樣做,我拿起「添加配置轉換」的web.config文件,並得到了4個Web CONFIGS:

enter image description here

但我不明白我怎麼可以指定任何人以任何發佈配置。例如,我無法找到正確的配置文件來爲開發發佈配置文件進行轉換。我怎樣才能做到這一點 ? 感謝您的任何建議。

+0

當發佈你選擇你想發佈您的配置,它會選擇相當於Web配置文件。 –

+0

@PaulKaram謝謝,但我認爲我需要在所有情況下使用「發佈」配置...所以我認爲這不是一個好的解決方案... – neustart47

+0

在您的MVC項目下,展開屬性,並且您會發現所有配置文件在PublishProfiles文件夾下。您可以直接編輯'mysite-environment - Web Deploy.pubxml'文件。我想'' Release'是你想要的嗎? – garethb

回答

1

我創建了一個新的網絡配置,我命名爲 「Web.development.config」。 這是我的項目文件的代碼轉換:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" /> 
    <Target Name="AfterCompile" Condition="exists('Web.$(Configuration).config')"> 
    <!-- Generate transformed app config in the intermediate directory --> 
    <TransformXml Source="Web.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="Web.$(Configuration).config" /> 
    <!-- Force build process to use the transformed configuration file from now on. --> 
    <ItemGroup> 
     <AppConfigWithTargetPath Remove="Web.config" /> 
     <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config"> 
     <TargetPath>$(TargetFileName).config</TargetPath> 
     </AppConfigWithTargetPath> 
    </ItemGroup> 
    </Target> 

所以用這個解決方案,您可以使用Web.<your publish profile name>.config

+1

感謝您花時間留下這個答案 - 幫助我非常。 – kape123

1

當您要創建發佈配置文件時,您會看到一個下拉列表,其中指定了它的模式。嘗試創建一個新的publich配置文件,你會看到。

enter image description here