MsDeploySkipRules being ignored on project publish

276 Views Asked by At

I want to exclude ALL files & folders in wwwroot\data from being published to my website folder. The files in my website folder are the latest copy and should never be overwritten when I publish the project.

Reference Microsoft documentation

The documentation indicates using this xml in .csproj file but I can't get it to work. I've tried putting this in both my .csproj file and .pubxml with no success.

What am I doing wrong? Can someone tell me if this actually works?

   <ItemGroup>
    <MsDeploySkipRules Include="CustomSkipFolder">
      <ObjectName>dirPath</ObjectName>
      <AbsolutePath>wwwroot\\data</AbsolutePath>
    </MsDeploySkipRules>
   </ItemGroup>

Here is my .pubxml file:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <DeleteExistingFiles>False</DeleteExistingFiles>
        <ExcludeApp_Data>False</ExcludeApp_Data>
        <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
        <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
        <LastUsedPlatform>Any CPU</LastUsedPlatform>
        <PublishProvider>FileSystem</PublishProvider>
        <PublishUrl>C:\www\VisualStudio2019-Core3</PublishUrl>
        <WebPublishMethod>FileSystem</WebPublishMethod>
        <SiteUrlToLaunchAfterPublish />
        <TargetFramework>netcoreapp3.1</TargetFramework>
        <ProjectGuid>881d6bfb-ed04-41d7-b600-0e26765ff90e</ProjectGuid>
        <SelfContained>false</SelfContained>
      </PropertyGroup>

Tried putting code here -->>

    </Project>

Here is my .csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RootNamespace>VisualStudio2019_Core3</RootNamespace>
    <UserSecretsId>93d2ec1f-4bcc-4aa5-ad65-4bdbdce5690a</UserSecretsId>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.3" />
    <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.5" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.2" />
    <PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.19.60" />
  </ItemGroup>

Tried putting code here -->>
  
</Project>

Additional information:

  • Visual Studio 2019
  • Web Application Core 3.1
  • Publishing via Studio menus...not command line.
1

There are 1 best solutions below

0
WhoAndWhy On

I used this (referring to my webapp) after end tag PropertyGroup

<ItemGroup>
    <Content Remove="appsettings.Development.*" />
    <Content Remove="bundleconfig.json" />
    <Content Remove="wwwroot\js\Site.js" />
    <Content Remove="wwwroot\js\webcam-easy.js" />
    <Content Remove="wwwroot\js\webcam-app.js" />
    <Content Remove="wwwroot\css\Site.css" />

    <Content Update="wwwroot\js\Site.js" CopyToPublishDirectory="Never" />
    <Content Update="wwwroot\js\webcam-easy.js" CopyToPublishDirectory="Never" />
    <Content Update="wwwroot\js\webcam-app.js" CopyToPublishDirectory="Never" />
    <Content Update="wwwroot\css\Site.css" CopyToPublishDirectory="Never" />

    <ResolvedFileToPublish Include="wwwroot\css\xxxxx.min.css">
        <RelativePath>wwwroot\css\xxxxx.min.css</RelativePath>
    </ResolvedFileToPublish>
    <ResolvedFileToPublish Include="wwwroot\js\xxxxx.min.js">
        <RelativePath>wwwroot\js\xxxxx.min.js</RelativePath>
    </ResolvedFileToPublish>
    <MsDeploySkipRules Include="connectionconfig">
        <ObjectName>filePath</ObjectName>
        <AbsolutePath>connection.json</AbsolutePath>
    </MsDeploySkipRules>
  </ItemGroup>