4

我正在尝试在 ASP.NET 文件系统发布中包含一个未包含在解决方案中的文件(它是从构建后脚本自动生成的)。根据这些说明,我应该能够使用元素在我的.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>元素,并且该文件未包含在发布中。注意元素下方的绿色波浪线:

在此处输入图像描述

当我将鼠标悬停在它上面时,会显示以下错误消息:

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 无法识别此元素?为了将此文件包含在我的文件系统发布中,我需要更改什么?

4

1 回答 1

5

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

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

于 2015-07-18T20:02:20.613 回答