다음을 통해 공유


Visual Studio를 사용하여 웹 응용 프로그램 프로젝트 배포를 위한 Web.config 변환 구문

이 항목의 구문에 대 한 참조 정보를 제공 xdt:Transform 및 xdt:Locator web.config에 사용 되는 특성 다음 제품에 대 한 파일 변환:

변환 파일은 Web.config 파일이 배포될 때 어떻게 변경되어야 하는지를 지정하는 XML 파일입니다. 변환 동작은 xdt 접두사에 매핑되는 XML-Document-Transform 네임스페이스에 정의된 XML 특성을 사용하여 지정합니다. XML-Document-Transform 네임스페이스는 Locator 및 Transform 특성을 정의합니다. Locator 특성은 특정한 방식으로 변경할 Web.config 요소 또는 요소 세트를 지정합니다. Transform 특성은 Locator 특성이 찾는 요소에 대해 수행할 작업을 지정합니다.

다음 예제에서는 연결 문자열을 변경하고 customErrors 요소를 대체하는 변환 파일의 내용을 보여 줍니다.

<?xml version="1.0"?>
<configuration xmlns:xdt="https://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="MyDB" 
      connectionString="value for the deployed Web.config file" 
      xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  </connectionStrings>
  <system.web>
    <customErrors defaultRedirect="GenericError.htm"
      mode="RemoteOnly" xdt:Transform="Replace">
      <error statusCode="500" redirect="InternalError.htm"/>
    </customErrors>
  </system.web>
</configuration>

변환 파일의 루트 요소는 이전 예제에 표시된 것처럼 여는 태그의 XML-Document-Transform 네임스페이스를 지정해야 합니다. Locator 및 Transform 요소는 배포된 Web.config 파일에서 재현되지 않습니다.

배포 하는 동안 변환을 적용 되지만 Visual Studio 변경 내용 미리 볼 수 있습니다. 솔루션 탐색기변환 파일 (예: Web.Release.config)를 마우스 오른쪽 단추로 클릭 하 고 선택 미리 보기 변환. Visual Studio 나란히 원래 Web.config 파일과 변환 된 Web.config 파일을 보여 줍니다.

Locator 특성 구문

다음의 각 단원에서는 단일 Locator 특성의 구문을 설명합니다.

Dd465326.collapse_all(ko-kr,VS.110).gif조건

현재 요소의 XPath 식에 추가되는 XPath 식을 지정합니다. 결합된 XPath 식과 일치하는 요소가 선택됩니다.

Dd465326.collapse_all(ko-kr,VS.110).gif구문

Locator="Condition(XPath expression)"

Dd465326.collapse_all(ko-kr,VS.110).gif예제

다음 예제에서는 name 특성 값이 oldname인 연결 문자열 요소 또는 값이 oldprovider인 providerName 특성을 선택하는 방법을 보여 줍니다. 배포된 Web.config 파일에서는 선택된 요소가 변환 파일에 지정된 요소로 대체됩니다.

<configuration xmlns:xdt="...">
  <connectionStrings>
    <add name="AWLT" connectionString="newstring"
       providerName="newprovider"
       xdt:Transform="Replace" 
       xdt:Locator="Condition(@name='oldname'
         or @providerName='oldprovider')" />
  </connectionStrings>
</configuration>

지정된 Condition 식의 결과로 배포 Web.config 파일에 적용되는 유효 XPath 식은 다음과 같습니다.

configuration/connectionStrings/add[@name='AWLT' or @providerName='System.Data.SqlClient']

이 식은 현재 요소(configuration/connectionStrings)에 대한 암시적 XPath 조건을 명시적으로 지정된 식과 결합한 결과입니다.

Dd465326.collapse_all(ko-kr,VS.110).gifMatch

지정된 특성에 대해 일치하는 값을 가진 요소를 선택합니다. 특성 이름을 여러 개 지정하면 지정된 모든 특성과 일치하는 요소만 선택됩니다.

Dd465326.collapse_all(ko-kr,VS.110).gif구문

Locator="Match(comma-delimited list of one or more attribute names)"

Dd465326.collapse_all(ko-kr,VS.110).gif예제

다음 예제에서는 배포 Web.config 파일에서 name 특성에 AWLT가 있는 연결 문자열 add 요소를 선택하는 방법을 보여 줍니다. 배포된 Web.config 파일에서는 선택된 요소가 변환 파일에 지정된 add 요소로 대체됩니다.

<configuration xmlns:xdt="...">
  <connectionStrings>
    <add name="AWLT" connectionString="newstring"
       providerName="newprovider"
       xdt:Transform="Replace" 
       xdt:Locator="Match(name)" />
  </connectionStrings>
</configuration>

Dd465326.collapse_all(ko-kr,VS.110).gifXPath

배포 Web.config 파일에 적용되는 절대 XPath 식을 지정합니다. Condition과 달리 지정된 식은 현재 요소에 해당하는 암시적 XPath 식에 추가되지 않습니다.

Dd465326.collapse_all(ko-kr,VS.110).gif구문

Locator="XPath(XPath expression)"

Dd465326.collapse_all(ko-kr,VS.110).gif예제

다음 예제에서는 Condition 키워드에 대해 이전 예제에서 선택한 것과 동일한 요소를 선택하는 방법을 보여 줍니다.

<configuration xmlns:xdt="...">
  <connectionStrings>
    <add name="AWLT" connectionString="newstring"
       providerName="newprovider"
       xdt:Transform="Replace" 
       xdt:Locator="XPath(configuration/connectionStrings[@name='AWLT'
         or @providerName='System.Data.SqlClient'])" />
  </connectionStrings>
</configuration>

변환 특성 구문

다음의 각 단원에서는 단일 Transform 특성의 구문을 설명합니다.

Dd465326.collapse_all(ko-kr,VS.110).gifReplace

선택된 요소를 변환 파일에 지정된 요소로 대체합니다. 둘 이상의 요소가 선택된 경우 첫 번째로 선택된 요소만 대체됩니다. Replace 키워드를 사용하는 방법에 대한 예제는 Locator 특성에 대한 예제를 참조하십시오.

Dd465326.collapse_all(ko-kr,VS.110).gif구문

Transform="Replace"

Dd465326.collapse_all(ko-kr,VS.110).gifInsert

변환 파일에 정의된 요소를 선택한 요소에 형제로 추가합니다. 새 요소는 컬렉션의 끝에 추가됩니다.

Dd465326.collapse_all(ko-kr,VS.110).gif구문

Transform="Insert"

Dd465326.collapse_all(ko-kr,VS.110).gif예제

다음 예제에서는 배포 Web.config 파일에서 모든 연결 문자열을 선택하는 방법을 보여 줍니다. 배포된 Web.config 파일에서 지정된 연결 문자열이 컬렉션의 끝에 추가됩니다.

<configuration xmlns:xdt="...">
  <connectionStrings>
    <add name="AWLT" connectionString="newstring"
       providerName="newprovider"
       xdt:Transform="Insert" />
  </connectionStrings>
</configuration>

Dd465326.collapse_all(ko-kr,VS.110).gifInsertBefore

변환 XML에 정의된 요소를 지정된 XPath 식에서 선택하는 요소 바로 앞에 삽입합니다. XPath 식은 배포 Web.config 파일에 전체적으로 적용되므로 절대 식이어야 하며, 현재 요소의 암시적 XPath 식에만 추가되지 않습니다.

Dd465326.collapse_all(ko-kr,VS.110).gif구문

Transform="InsertBefore(XPath expression)"

Dd465326.collapse_all(ko-kr,VS.110).gif예제

다음 예제에서는 선택 하는 방법의 deny 모든 사용자에 게 액세스를 거부 하는 요소입니다. 다음 삽입은 allow 요소 앞의 deny 관리자에 게 액세스를 부여 하기 위해 요소.

<configuration xmlns:xdt="...">
  <authorization>
    <allow roles="Admins"
      xdt:Transform="InsertBefore(/configuration/system.web/authorization/deny[@users='*'])" />
  </authorization>
</configuration>

Dd465326.collapse_all(ko-kr,VS.110).gifInsertAfter

변환 XML에 정의된 요소를 지정된 XPath 식에서 선택하는 요소 바로 뒤에 삽입합니다. XPath 식은 배포 Web.config 파일에 전체적으로 적용되므로 절대 식이어야 하며, 현재 요소의 암시적 XPath 식에 추가되지 않습니다.

Dd465326.collapse_all(ko-kr,VS.110).gif구문

Transform="InsertAfter(XPath expression)"

Dd465326.collapse_all(ko-kr,VS.110).gif예제

다음 예제에서는 관리자에게 액세스 권한을 부여하고 지정된 사용자에 대한 액세스를 거부하는 deny 요소를 자신 뒤에 삽입하는 allow요소를 선택하는 방법을 보여 줍니다.

<configuration xmlns:xdt="...">
  <authorization>
    <deny users="UserName"
      xdt:Transform="InsertAfter
        (/configuration/system.web/authorization/allow[@roles='Admins'])" />
  </authorization>
</configuration>

Dd465326.collapse_all(ko-kr,VS.110).gif제거

선택한 요소를 제거합니다. 요소를 여러 개 선택한 경우 첫 번째 요소를 제거합니다.

Dd465326.collapse_all(ko-kr,VS.110).gif구문

Transform="Remove"

Dd465326.collapse_all(ko-kr,VS.110).gif예제

다음 예제에서는 배포 Web.config 파일에서 모든 연결 문자열 add 요소를 선택하는 방법을 보여 줍니다. 배포된 Web.config 파일에서 첫 번째 연결 문자열 요소만 제거됩니다.

<configuration xmlns:xdt="...">
  <connectionStrings>
    <add xdt:Transform="Remove" />
  </connectionStrings>
</configuration>

Dd465326.collapse_all(ko-kr,VS.110).gifRemoveAll

선택한 요소를 제거합니다.

Dd465326.collapse_all(ko-kr,VS.110).gif구문

Transform="RemoveAll"

Dd465326.collapse_all(ko-kr,VS.110).gif예제

다음 예제에서는 배포 Web.config 파일에서 모든 연결 문자열을 선택하는 방법을 보여 줍니다. 배포된 Web.config 파일에서 모든 요소가 제거됩니다.

<configuration xmlns:xdt="...">
  <connectionStrings>
    <add xdt:Transform="RemoveAll" />
  </connectionStrings>
</configuration>

Dd465326.collapse_all(ko-kr,VS.110).gifRemoveAttributes

선택한 요소에서 지정된 특성을 제거합니다.

Dd465326.collapse_all(ko-kr,VS.110).gif구문

Transform="RemoveAttributes(comma-delimited list of one or more attribute names)"

Dd465326.collapse_all(ko-kr,VS.110).gif예제

다음 예제에서는 배포 Web.config 파일에서 모든 compilation 요소를 선택하는 방법을 보여 줍니다. 구성 파일에는 compilation 요소가 하나만 존재할 수 있으므로 Locator 특성을 지정할 필요가 없습니다. 배포된 Web.config 파일에서 debug 및 batch 특성이 compilation 요소에서 제거됩니다.

<configuration xmlns:xdt="...">
  <compilation 
    xdt:Transform="RemoveAttributes(debug,batch)">
  </compilation>
</configuration>

Dd465326.collapse_all(ko-kr,VS.110).gifSetAttributes

선택한 요소에 대한 특성을 지정된 값으로 설정합니다. Replace 변환 특성은 모든 특성을 포함하여 전체 요소를 대체합니다. 반대로 SetAttributes 특성을 사용하면 요소를 그대로 두고 선택된 특성만 변경할 수 있습니다. 변경 하는 특성을 지정 하지 않으면 변환 파일의 요소에 있는 특성을 모두 변경 됩니다.

SetAttributes 변환 선택한 모든 요소에 영향을 줍니다. 이 동작은 다릅니다는 Replace 요소를 여러 개 선택 하면 첫 번째 선택한 요소에 영향을 미치는 변형 특성.

Dd465326.collapse_all(ko-kr,VS.110).gif구문

Transform="SetAttributes(comma-delimited list of one or more attribute names)"

Dd465326.collapse_all(ko-kr,VS.110).gif예제

다음 예제에서는 배포 Web.config 파일에서 모든 compilation 요소를 선택하는 방법을 보여 줍니다. 구성 파일에는 compilation 요소가 하나만 존재할 수 있으므로 Locator 특성을 지정할 필요가 없습니다. 배포된 Web.config 파일에서 compilation 요소의 batch 특성 값이 false로 설정됩니다.

<configuration xmlns:xdt="...">
  <compilation 
    batch="false"
    xdt:Transform="SetAttributes(batch)">
  </compilation>
</configuration>

Locator 특성 생략

Locator 특성은 선택적입니다. Locator 특성을 지정하지 않으면 변경될 요소가 Transform 특성이 지정되는 요소를 통해 암시적으로 지정됩니다. 다음 예제에서는 Locator 특성이 별도로 지정되어 있지 않기 때문에 전체 system.web 요소가 대체됩니다.

<?xml version="1.0"?>
<configuration xmlns:xdt="https://schemas.microsoft.com/XML-Document-Transform">
  <system.web xdt:Transform="Replace">
    <customErrors defaultRedirect="GenericError.htm"
      mode="RemoteOnly">
      <error statusCode="500" redirect="InternalError.htm"/>
    </customErrors>
  </system.web>
</configuration>

개별 요소에서 Transform 및 Locator 특성 사용

Transform 특성을 Locator 요소와 동일한 요소에서 설정할 필요가 없습니다. 자식 요소를 사용할 요소를 선택하기 위해 부모 요소에서 Locator 요소를 지정할 수 있습니다. 그런 다음 변경 내용을 자식에 적용하도록 자식 요소에서 Transform 특성을 지정할 수 있습니다.

다음 예제에서는 Locator 특성을 사용하여 지정된 경로에 대한 location 요소를 선택하는 방법을 보여 줍니다. 선택한 location 요소의 자식 요소만 변환됩니다.

<configuration xmlns:xdt="...">
  <location path="C:\MySite\Admin" xdt:Locator="Match(path)"> 
    <system.web>
      <pages viewStateEncryptionMode="Always"
        xdt:Transform="SetAttributes(viewStateEncryptionMode)" />
    </system.web> 
  </location> 
</configuration>

Locator 특성은 지정했지만 동일한 요소 또는 자식 요소에서 Transform 특성을 지정하지 않은 경우에는 변경되지 않습니다.

참고

부모 요소의 Transform 특성은 Transform을 지정하지 않은 경우에도 자식 요소에 영향을 줄 수 있습니다.예를 들어 system.web 요소에 xdt:Transform="Replace" 특성을 삽입하면 system.web 요소의 모든 자식 요소가 변환 파일의 내용으로 대체됩니다.

참고 항목

개념

Visual Studio 및 ASP.NET에 대한 웹 배포 콘텐츠 맵

기타 리소스

Web.config 파일 변환 (자습서 ASP.NET 사이트에서)