asp.net - <_CustomFiles> 元素在 .pubxml 中无法识别

标签 asp.net visual-studio msbuild publish pubxml

我正在尝试在解决方案中未包含的 ASP.NET 文件系统发布中包含一个文件(它是从构建后脚本自动生成的)。根据 these instructions ,我应该能够在我的 .pubxml 中添加对文件的引用使用 <_CustomFiles> 的定义元素。这是我的 .pubxml文件看起来像:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <publishUrl>(publish URL here)</publishUrl>
    <DeleteExistingFiles>False</DeleteExistingFiles>
  </PropertyGroup>

  <PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForPackageDependsOn>

    <CopyAllFilesToSingleFolderForMsdeployDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForMsdeployDependsOn>
  </PropertyGroup>

  <Target Name="CustomCollectFiles">
    <ItemGroup>
      <_CustomFiles Include="scripts\app.min.js" />

      <FilesForPackagingFromProject  Include="%(_CustomFiles.Identity)">
        <DestinationRelativePath>Extra Files\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>
</Project>

第二个<PropertyGroup><Target>元素是我添加的。

但是,Visual Studio 无法识别 <_CustomFiles>元素并且文件未包含在发布中。注意元素下方的绿色波浪线:

enter image description here

当我将鼠标悬停在它上面时,会显示以下错误消息:
The element 'ItemGroup' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003' has invalid child element '_CustomFiles' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003'

为什么 Visual Studio 无法识别此元素?我需要更改什么才能将此文件包含在我的文件系统发布中?

最佳答案

弄清楚了。我误解了 <_CustomFiles> 的目的元素。似乎这是一个自定义元素(即不是 XML 模式的一部分,因此是 VS 警告)用于将信息传递给 <FilesForPackaginFromProject>它下面的元素。

事实证明这种方法对我有用,我只是错误地使用了相对路径。

关于asp.net - <_CustomFiles> 元素在 .pubxml 中无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31483974/

相关文章:

c++ - '警告 C4709 : comma operator within array index expression' - but no comma to be seen anywhere!

windows - Visual Studio 忘记了窗口设置并弄得一团糟

c# - 我应该如何在 msbuild 脚本中引用 sn.exe?

.net - 缺少 MSBuild "sgen.exe"

windows - 当从 Visual Studio 2019 IDE 启动提示时,为什么 wsl(用于 linux 的 Windows 子系统)在命令提示符中不可用?

asp.net - 我可以使用 msbuild 打包带有发布配置文件的网站并跳过 web.config 转换吗?

c# - 如何在 Entity Framework Core 中执行 SQL 查询而不修改上下文类

javascript - Angular Modal 仅适用于 Index.html

asp.net - Request() 和 Request.Form() 有什么区别?

c# - asp.net paypal重定向设置值到mysql