MsDeploySkipRules 在项目发布时被忽略

问题描述

我想排除 wwwroot\data 中的所有文件文件夹发布到我的网站文件夹。我网站文件夹中的文件是最新的副本,在我发布项目时不应被覆盖。

Reference Microsoft documentation

文档表明在 .csproj 文件中使用了这个 xml,但我无法让它工作。我试过把它放在我的 .csproj 文件.pubxml 中,但没有成功。

我做错了什么?有人能告诉我这是否真的有效吗?

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

这是我的 .pubxml 文件

    <?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>

这是我的 .csproj 文件

<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>

附加信息:

  • Visual Studio 2019
  • Web 应用程序核心 3.1
  • 通过 Studio 菜单发布...而不是命令行。

解决方法

我在结束标记 PropertyGroup 之后使用了这个(指的是我的 web 应用程序)

<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>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...