Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

Exclude files from web site publish in Visual Studio

Can I exclude a folder or files when I publish a web site in Visual Studio 2005? I have various resources that I want to keep at hand in the Solution Explorer, such as alternate config files for various environments, but I don't really want to publish them to the server. Is there some way to exclude them? When using other project types, such as a .dll assembly, I can set a file's Build Action property to "None" and its Copy to Output Directory property to "Do not copy". I cannot find any similar settings for files in a web site.

If the IDE does not offer this feature, does anyone have good technique for handling such files?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Exclude files and folders by adding ExcludeFilesFromDeployment and ExcludeFoldersFromDeployment elements to your project file (.csproj, .vbproj, etc). You will need to edit the file in a text editor, or in Visual Studio by unloading the project and then editing it.

Add the tags anywhere within the appropriate PropertyGroup (Debug, Release, etc) as shown below:

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

Wildcards are supported.

To explain the example above:

  • The 1st ExcludeFilesFromDeployment excludes File1.aspx (in root of project) and Folder2File2.aspx (Folder2 is in the root of the project)
  • The 2nd ExcludeFilesFromDeployment excludes all files within any folder named .svn and any of its subfolders
  • The ExcludeFoldersFromDeployment excludes folders named Folder1 (in root of project) and Folder2Folder2a (Folder2 is in the root of the project)

For more info see MSDN blog post Web Deployment: Excluding Files and Folders via the Web Application’s Project File


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...