Reputation: 230038
When I publish my Asp.Net MVC website to the production server (via VS2008), the web.config & castle.xml files are overwritten. The content of these files is obviously different between my local dev environment and the production server.
How do I prevent these files from being published?
Upvotes: 20
Views: 13260
Reputation: 1668
<PropertyGroup>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>
Select web.config and change in Properties window:
"Copy to Output Directory"="Do not copy"
Upvotes: 4
Reputation: 9586
We use a Jenkins pipeline to deploy .Net Core/Framework apps to an ISS server.
One of the steps defines a Power Shell script that calls MSBuild
with the specified project and publish profile.
Adding the ExcludeFilesFromDeployment
tag to the Publish Profile script worked.
WebDeploy-Staging.pubxml:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- All the other tags excluded for brevity -->
<ExcludeFilesFromDeployment>Web.config</ExcludeFilesFromDeployment>
</PropertyGroup>
</Project>
</Project>
Upvotes: 0
Reputation: 27312
I solved it by adding this exclusion:
<ExcludeFilesFromDeployment>Web.config</ExcludeFilesFromDeployment>
to the project file (.csproj or .vbproj), inside these nodes:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
and
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
See Web Deployment: Excluding Files and Folders via the Web Application’s Project File.
Upvotes: 3
Reputation: 415765
Never publish directly from Visual Studio to a production server!
Publish to a testing server for QA to look at, and then copy from QA to production (for an existing web site with no iis changes, it's just a matter of copying files).
Where I'm at, we also keep these published files under revision control separately, and so when QA signs off on a build the deployment process is simply checking out the files from source control on the production server.
Upvotes: -1
Reputation: 9736
In Visual Studio solution explorer, go to your web.config file's properties. Make sure "Build Action" is "None" and "Copy to Output Directory" is "Do not copy".
If you ever want to update it in the future you'll have to do it manually or change "Build Action" back to "Content". The next time you build (or publish) it will overwrite it.
Upvotes: 29