JanDotNet
JanDotNet

Reputation: 4016

How to exclude APP_DATA directory from publishing using custom target "PublishToFileSystem"

I am using a custom target for publishing my web site to a local folder.

The target (found here) looks like:

<Target Name="PublishToFileSystem"
        DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder">
    <Error Condition="'$(PublishDestination)'==''"
           Text="The PublishDestination property must be set to the intended publishing destination." />
    <MakeDir Condition="!Exists($(PublishDestination))"
             Directories="$(PublishDestination)" />

    <ItemGroup>
        <PublishFiles Include="$(_PackageTempDir)\**\*.*" />
    </ItemGroup>

    <Copy SourceFiles="@(PublishFiles)"
          DestinationFiles="@(PublishFiles->'$(PublishDestination)\%(RecursiveDir)%(Filename)%(Extension)')"
          SkipUnchangedFiles="True" />
</Target>

The corresponding msbuild command looks like:

msbuild projectfile.csproj /p:DeployOnBuild=true /p:VisualStudioVersion=14.0 /p:configuration=Release /p:PublishDestination=C:\inetpub\wwwroot\WebSite /T:PublishToFileSystem

That works fine so far. However, I would like to exclude the APP_DATA directory from publishing.

So, is there a way to exclude the APP_DATA directory from publishing? Maybe by excluding it from the file set defined with <PublishFiles Include="$(_PackageTempDir)\**\*.*" />?

Environment: Visual Studio 2015 MSBuild Tools 2015

Upvotes: 2

Views: 4389

Answers (3)

dwp4ge
dwp4ge

Reputation: 2003

The easiest way I found is to set this inside the publish profile.

<ExcludeApp_Data>False</ExcludeApp_Data>

enter image description here

Upvotes: 3

JanDotNet
JanDotNet

Reputation: 4016

It is possible to set the option (suggested by @Vipin Rathore) within the project file:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <ExcludeFoldersFromDeployment>APP_DATA</ExcludeFoldersFromDeployment>
</PropertyGroup>

Upvotes: 0

Vipin Rathore
Vipin Rathore

Reputation: 158

You can do it from solution property. Just right click on solution and choose its property. You will get Package/Publish tab there you just need to check "Exclude files from the App_Data Folder". You can check at attached screen shot. Hope this can help you.enter image description here

Upvotes: 2

Related Questions