1

을 게시 웹 API에 적용되지 :구성 변환 내가이 설정을 포함하는 ASP.NET 웹 API 프로젝트를 변환 한

  • Web.Live.config을
  • Web.UAT.config

게시 할 때 Live 또는 UAT 구성을 선택하면 렌더링 된 web.config 파일에 변환이 적용되지 않습니다.

변환 설정을 확인했으며 name, xdt:Transformxdt:Locator이 올바른지 확인했습니다. 내 web.config에서

내가 가진 내 web.Live.config에서

<connectionStrings> 
    <add name="foo" providerName="System.Data.SqlClient" connectionString="[main connection string]" /> 
</connectionStrings> 

내가 가진 :

<?xml version="1.0" encoding="utf-8"?> 

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> 

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 

    <connectionStrings> 
    <add name="foo" 
     connectionString="[live connection string]" 
     xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> 
    </connectionStrings> 

    <system.web> 
    <compilation xdt:Transform="RemoveAttributes(debug)" /> 
    <!-- 
     In the example below, the "Replace" transform will replace the entire 
     <customErrors> section of your web.config file. 
     Note that because there is only one customErrors section under the 
     <system.web> node, there is no need to use the "xdt:Locator" attribute. 

     <customErrors defaultRedirect="GenericError.htm" 
     mode="RemoteOnly" xdt:Transform="Replace"> 
     <error statusCode="500" redirect="InternalError.htm"/> 
     </customErrors> 
    --> 
    </system.web> 
</configuration> 

그러나 내 게시 된 연결 문자열은 여전히 ​​Live을 선택한 경우에도 다음과 같이 표시

<connectionStrings> 
    <add name="foo" providerName="System.Data.SqlClient" connectionString="[main connection string]" /> 
</connectionStrings> 

가능한 이유는 무엇입니까? 이 일이 일어나기 위해서?

+1

은 어떻게 게시? "프로필 게시"를 사용하고 있습니까? 게시 '연결'유형 (예 : 웹 배포)에 따라 연결 문자열을 설정할 수있는 구체적인 '설정'이 표시됩니다. 확실하지는 않지만 아마도 이것이 기본 연결 문자열로 설정되어 있고 구성 변환보다 우선 순위가 높은지 궁금합니다. 최소한 보일만한 가치가 있습니다 ("런타임에이 연결 문자열 사용"선택을 취소하십시오). 그 외, 설정 파일 자체는 괜찮아 보입니다 – musefan

+0

@musefan 감사합니다.'appSettings'에서'xdt : Transform = "Replace"를 시도해 보았고이 변경 사항이 렌더링 된 설정에 적용되었습니다! 따라서 연결 문자열 부분에 문제가 있습니다. 그러나 VS2012에서 "미리보기 변환"을 수행하면 변환이 적용됩니다. – Curt

+0

허, 변환 미리보기를 할 수 있는지 몰랐습니다. 어쨌든, 어떻게 출판하고 있습니까? 미리보기가 작동하면 변환 후에 다른 것을 덮어 써야합니다. – musefan

답변

1

이 경우 문제는 빌드 구성 프로필을 변경하면 자동으로 게시 프로필이 일치하도록 업데이트 된 것으로 가정합니다.이 경우는 그렇지 않습니다.

게시 프로필이 하나 인 경우 빌드를 만들 때마다 "설정"> "게시"> "구성"설정을 수동으로 변경해야합니다.이 설정 변경 파일은 적용되는 구성 변환 파일을 결정합니다.

이 문제를 처리하는 방법으로 각 게시 구성마다 하나씩 프로필을 게시하는 것이 좋습니다. 예를 들어, "Debug"및 "Release"또는이 경우 "Live"및 "UAT"입니다. 이렇게하면 게시 프로세스 중에 두 프로필을 쉽게 전환 할 수 있습니다.

변환을 관리하는 것보다이 접근법에 다른 이점이 있다는 점은 주목할 가치가 있습니다. 서로 다른 빌드에 대해 서로 다른 프로파일을 사용하면 다른 대상도 지정할 수 있습니다. 예를 들어 웹 배포 방법을 사용하는 경우 대상 환경 (예 : 테스트 또는 생산)에 따라 응용 프로그램을 다른 서버로 보낼 수 있습니다.

1

적용되는 변환은 "디버그 ","Test "구성이 아닙니다. 나는 수동으로 일부 파일을 편집하여 해결했다. 나는 어떤 것이 틀렸는 지, 어떻게 잘못되었는지는 모르지만, 이것이 내가 어떻게 해결 했는가.

나는 "디버그"에서의 .sln을 변경 :

{96...D2A}.Test|Any CPU.ActiveCfg = Debug|Any CPU 
    {96...D2A}.Test|Any CPU.Build.0 = Debug|Any CPU 
    {96...D2A}.Test|Mixed Platforms.ActiveCfg = Debug|Any CPU 
    {96...D2A}.Test|Mixed Platforms.Build.0 = Debug|Any CPU 
    {96...D2A}.Test|x86.ActiveCfg = Debug|Any CPU 

는 "테스트"로 :

{96...D2A}.Test|Any CPU.ActiveCfg = Test|Any CPU 
    {96...D2A}.Test|Any CPU.Build.0 = Test|Any CPU 
    {96...D2A}.Test|Mixed Platforms.ActiveCfg = Test|Any CPU 
    {96...D2A}.Test|Mixed Platforms.Build.0 = Test|Any CPU 
    {96...D2A}.Test|x86.ActiveCfg = Test|Any CPU 

내가에서 테스트 구성을 변경했습니다.

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Test|AnyCPU'"> 
    <DebugSymbols>true</DebugSymbols> 
    <OutputPath>bin\</OutputPath> 
    <DefineConstants>DEBUG;TRACE</DefineConstants> 
    <DebugType>full</DebugType> 
    <PlatformTarget>AnyCPU</PlatformTarget> 
    <ErrorReport>prompt</ErrorReport> 
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> 
</PropertyGroup> 

에 (나는이 모든 제거 매개 변수/의미 의미 확실하지 오전) :에서 csproj

:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Test|AnyCPU'"> 
    <OutputPath>bin\</OutputPath> 
    <DefineConstants>DEBUG;TRACE</DefineConstants> 
</PropertyGroup> 

나는에서 .csproj에 Web.Test.config 변경

<None Include="Web.Test.config"> 
    <DependentUpon>Web.config</DependentUpon> 
</None> 

사람 :

<Content Include="Web.Test.config"> 
    <DependentUpon>Web.config</DependentUpon> 
</Content> 
+0

에서 으로 변경하면 파일이 배포 된 사이트로 복사되지만 나쁘지는 않습니다. – PeteN