Nice programing

Visual Studio의 웹 사이트 게시에서 파일 제외

nicepro 2020. 10. 25. 13:03
반응형

Visual Studio의 웹 사이트 게시에서 파일 제외


Visual Studio 2005에서 웹 사이트를 게시 할 때 폴더 또는 파일을 제외 할 수 있습니까? 다양한 환경에 대한 대체 구성 파일과 같이 솔루션 탐색기에 보관하고 싶은 다양한 리소스가 있지만 실제로 서버에 게시하고 싶지는 않습니다. 그들을 제외하는 방법이 있습니까? .dll 어셈블리와 같은 다른 프로젝트 유형을 사용하는 경우 파일의 빌드 작업 속성을 "없음"으로 설정하고 출력 디렉터리에 복사 속성을 "복사 안 함"으로 설정할 수 있습니다. 웹 사이트에서 파일에 대한 유사한 설정을 찾을 수 없습니다.

IDE에서이 기능을 제공하지 않는 경우 이러한 파일을 처리하는 데 좋은 기술이있는 사람이 있습니까?


확장자를 기반으로 파일을 식별 할 수 있는 경우 web.configbuildproviders 태그를 사용하여 이를 구성 할 수 있습니다 . 확장을 추가하고 ForceCopyBuildProvider에 매핑합니다. 예를 들어 게시 작업으로 복사 할 .xml 파일을 구성하려면 다음을 수행합니다.

<configuration>...
    <system.web>...
        <compilation>...
            <buildProviders>
                <remove extension=".xml" />
                <add extension=".xml" type="System.Web.Compilation.ForceCopyBuildProvider" />
            </buildProviders>

지정된 파일이 복사되지 않도록하려면 동일한 작업을 수행하지만 System.Web.Compilation.IgnoreFileBuildProvider를 형식으로 사용합니다.


프로젝트 파일 (.csproj, .vbproj 등)에 ExcludeFilesFromDeploymentExcludeFoldersFromDeployment요소를 추가하여 파일과 폴더를 제외합니다 . PropertyGroup아래와 같이 적절한 (디버그, 릴리스 등) 내의 아무 곳에 나 추가하십시오 .

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 
  ... 
  <ExcludeFilesFromDeployment>File1.aspx;Folder2\File2.aspx</ExcludeFilesFromDeployment> 
  <ExcludeFilesFromDeployment>**\.svn\**\*.*</ExcludeFilesFromDeployment>
  <ExcludeFoldersFromDeployment>Folder1;Folder2\Folder2a</ExcludeFoldersFromDeployment> 
</PropertyGroup>

와일드 카드가 지원됩니다.

위의 예를 설명하려면 :

  • 첫 번째 ExcludeFilesFromDeployment제외 File1.aspx(프로젝트 루트에 있음) 및 Folder2\File2.aspx( Folder2프로젝트 루트에 있음)
  • 두 번째는 ExcludeFilesFromDeployment이름이 지정된 폴더 .svn와 하위 폴더 내의 모든 파일을 제외합니다.
  • ExcludeFoldersFromDeployment제외라는 이름의 폴더 Folder1(프로젝트의 루트에) 및 Folder2\Folder2a( Folder2프로젝트의 루트에)

자세한 내용은 MSDN 블로그 게시물 웹 배포 : 웹 응용 프로그램의 프로젝트 파일을 통해 파일 및 폴더 제외를 참조하십시오 .


놀랍게도 Visual Studio 2012에 대한 답은 여기에 없습니다.

  • 녹색 확인 표시가있는 답은 답이 아닙니다.

  • 가장 높은 "제공된"답변은 2010 년의 기사를 참조하며 현재 잘못된 csproj 프로젝트 파일을 편집해야한다고 말합니다. ExcludeFoldersFromDeployment XML 요소를 Visual Studio 2012 csproj 파일에 추가했지만 아무 작업도 수행하지 않고 요소가 잘못된 것으로 간주되었습니다 .ExcludeFoldersFromDeployment가 보이는 .pubxml 파일로 이동 되었기 때문입니다.

웹 응용 프로그램 및 웹 사이트의 경우 .pubxml 파일을 편집합니다!

내 대답을 따르거나 나중에 찾은이 가이드를 사용해 볼 수 있습니다. http://www.leniel.net/2014/05/using-msdeploy-publish-profile-pubxml-to-create-an-empty-folder-structure- on-iis-and-skip-deleting-it-with-msdeployskiprules.html # sthash.MSsQD8U1.dpbs

예, 웹 사이트 프로젝트뿐만 아니라 웹 사이트에서도이 작업을 수행 할 수 있습니다. 저는 인터넷에서 Visual Studio 웹 사이트 (웹 사이트 프로젝트가 아님)에서이 찾기 어려운 제외 기능을 찾기 위해 오랜 시간을 보냈으며 이전에 이것이 불가능하다고 결론을 내렸지 만 다음과 같이 보입니다.

~ / Properties / PublishProfiles for Web Application Projects 및 ~ / App_Data / PublishProfiles for Websites에있는 [mypublishwebsitename] .pubxml 파일에서 다음을 추가하면됩니다.

  <ExcludeFilesFromDeployment>File1.aspx;Folder2\File2.aspx</ExcludeFilesFromDeployment> 
 <ExcludeFoldersFromDeployment>Folder1;Folder2\Folder2a</ExcludeFoldersFromDeployment>

<PropertyGroup>.pubxml 파일 의 기본 요소에 자식으로 추가합니다. 릴리스 또는 디버그와 같은 특정 빌드 유형을 입력하지 않는 한 새 요소를 추가 할 필요가 없습니다.

하지만 기다려!!!

게시 구성에서 다음 설정을 사용하여 대상 / 대상 서버에서 파일을 제거하는 경우 :

여기에 이미지 설명 입력

그런 다음 웹 게시 프로세스는 소스 / 대상 서버에서 제외 된 항목 (예 : <ExcludeFoldersFromDeployment><ExcludeFilesFromDeployment>!

MsDeploy 건너 뛰기 규칙을 해결하려면

첫째, Web Publish는 게시 할 때 MSBuild가 아닌 다른 것을 사용하지만 (작업 IO 또는 이와 유사한 것) 버그가 있으며 건너 뛰기 규칙을 인식하지 않으므로 .pubxml에 추가해야합니다.

<PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
</PropertyGroup>

나는 계속 것 <WebPublishMethod>자체에 <PropertyGroup>당신은 당신이 하나 개있을 수 있다고 생각 것, <PropertyGroup>내가 이동 될 때까지 호출되는되지 않은 사용자의 .pubxml하지만 내 건너 뛰기 규칙의 요소를 <WebPublishMethod>그 자체로 <PropertyGroup>요소입니다. 예, 미쳤습니다.하지만 Web Publish가 서버에서 폴더 / 파일을 제외하고 삭제하지 않기 위해이 모든 작업을 수행해야한다는 사실은 미쳤습니다.

이제 내 .pubxml의 실제 SkipRules, ExcludeFolders 및 ExcludeFiles 선언 :

<ExcludeFoldersFromDeployment>Config</ExcludeFoldersFromDeployment>
<ExcludeFoldersFromDeployment>Photos</ExcludeFoldersFromDeployment>
<ExcludeFoldersFromDeployment>Temp</ExcludeFoldersFromDeployment>
<ExcludeFilesFromDeployment>Web.config</ExcludeFilesFromDeployment>
 <AfterAddIisSettingAndFileContentsToSourceManifest>AddCustomSkipRules</AfterAddIisSettingAndFileContentsToSourceManifest>

이제 건너 뛰기 규칙 ( <Target><Project>.pubxml 의 자식 임) : ( 모든 작업에 대해 건너 뛰기 위해 비워 둘 수 <SkipAction>있지만 테스트하지 않았고 확실하지 않습니다.

  <Target Name="AddCustomSkipRules">
    <Message Text="Adding Custom Skip Rules" />
    <ItemGroup>
      <MsDeploySkipRules Include="SkipConfigFolder">
        <SkipAction>Delete</SkipAction>
        <ObjectName>dirPath</ObjectName>
        <AbsolutePath>$(_DestinationContentPath)\\Config</AbsolutePath>
        <XPath>
        </XPath>
      </MsDeploySkipRules>
      <MsDeploySkipRules Include="SkipPhotosFolder">
        <SkipAction>Delete</SkipAction>
        <ObjectName>dirPath</ObjectName>
        <AbsolutePath>$(_DestinationContentPath)\\Photos</AbsolutePath>
        <XPath>
        </XPath>
      </MsDeploySkipRules>
      <MsDeploySkipRules Include="SkipWebConfig">
        <SkipAction>Delete</SkipAction>
        <ObjectName>filePath</ObjectName>
        <AbsolutePath>$(_DestinationContentPath)\\Web\.config</AbsolutePath>
        <XPath>
        </XPath>
      </MsDeploySkipRules>
      <MsDeploySkipRules Include="SkipWebConfig">
        <SkipAction>Delete</SkipAction>
        <ObjectName>dirPath</ObjectName>
        <AbsolutePath>$(_DestinationContentPath)\\Temp</AbsolutePath>
        <XPath>
        </XPath>
      </MsDeploySkipRules>
    </ItemGroup>
  </Target>

그리고 .백 슬래시로 filePath Skip 규칙 을 이스케이프하는 것을 잊지 마십시오 .


나는 같은 문제로 어려움을 겪고 마침내 웹 사이트를 웹 응용 프로그램으로 변환하는 방아쇠를 당겼습니다. 이 작업을 수행하면 빌드 작업과 같은 IDE의 모든 이점을 얻었으며 부팅 속도가 빨라졌습니다 (웹 사이트 유효성 검사가 더 이상 필요하지 않음).

Step 1: Convert your 'web site' to a 'web application'. To convert it I just created a new "web application", blew away all the files it created automatically, and copied and pasted my web site in. This worked fine. Note that report files will need to have their Build Action set to "Content" instead of "none".

Step 2: Now you can set any files "Build Action" property.

Hope this helps.


In Visual Studio 2013 I found Keith's answer, adding the ExcludeFoldersFromDeployment element to the project file, didn't work (I hadn't read Brian Ogden's answer which says this). However, I found I could exclude a text file when publishing in Visual Studio 2013 by just setting the following properties on the text file itself:

1) Build Action: None

2) Copy to Output Directory: Do not copy

Initially I tried setting the Copy to Output Directory property by itself but that didn't work when the Build Action was set to the default value, Content. When I then set the Build Action to None the text file was no longer copied to the destination folder when I published.

To view these properties in the Visual Studio GUI, in the Solution Explorer right-click on the file you want to exclude and select Properties from the context menu.


I think you only have two options here:

  • Use the 'Exclude From Project' feature. This isn't ideal because the project item will be excluded from any integrated IDE source control operations. You would need to click the 'Show All Files' button on the Solution window if you need to see the files in Solution Explorer, but that also shows files and folders you're not interested in.
  • Use a post-build event script to remove any project items you don't want to be published (assuming you're publishing to a local folder then uploading to the server).

I've been through this before and couldn't come up with anything really elegant.


The feature you are looking exists if your project is created as a "Web Application". Web Site "projects" are just a collection of files that are thought of as 1:1 with what gets deployed to a web server.

In terms of functionality both are the same, however a web application compiles all source code to a DLL, instead of the naked source code files being copied to the web server and compiled as needed.


For Visual Studio 2017, WebApp Publish, first create a standard file system publish profile. Go to the App_Data\PublishProfiles\ folder and edit the [profilename].pubxml file.

Add

<ExcludeFilesFromDeployment>[file1.ext];[file2.ext];[file(n).ext]</ExcludeFilesFromDeployment>

under the tag<PropertyGroup> You can only specify this tag once, otherwise it will only take the last one's values.

Example:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>True</ExcludeApp_Data>
    <publishUrl>C:\inetput\mysite</publishUrl>
    <DeleteExistingFiles>False</DeleteExistingFiles>
    <ExcludeFilesFromDeployment>web.config;mysite.sln;App_Code\DevClass.cs;</ExcludeFilesFromDeployment>
  </PropertyGroup>
</Project>

Make sure that the tag DeleteExistingFiles is set to False


In Visual Studio 2017 (15.9.3 in my case) the manipulation of the .csproj-File works fine indeed! No need to modify the pubxml.

You can then construct pretty nice settings in the .csproj-File using the PropertyGroup condition, e.g.:

  <PropertyGroup Condition="$(Configuration.StartsWith('Pub_'))">
    <ExcludeFoldersFromDeployment>Samples</ExcludeFoldersFromDeployment>
  </PropertyGroup>

excludes the "Samples" folder from all deployments with configurations starting with "Pub_"...


As a contemporary answer, in Visual Studio 2017 with a .net core site:

CopyToPublishDirectory가 절대없는 csproj에서 게시에서 제외 할 수 있습니다.

  <ItemGroup>
    <Content Update="appsettings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </Content>
    <Content Update="appsettings.Local.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </Content>
  </ItemGroup>

이에 대해서는 https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-2.2 에서 자세히 설명합니다.

<PropertyGroup>
    <ExcludeFilesFromDeployment>appsettings.Local.json</ExcludeFilesFromDeployment>
</PropertyGroup>

이전 제안은 저에게 효과가 없었습니다. Visual Studio가 이제 다른 게시 메커니즘을 사용하고 있기 때문에 저는 "dotnet 게시"CLI 도구 또는 그 아래에있는 동등한 도구를 사용한다고 생각합니다.

참고 URL : https://stackoverflow.com/questions/650875/exclude-files-from-web-site-publish-in-visual-studio

반응형