【问题标题】:adding extra files to published MVC API project向已发布的 MVC API 项目添加额外文件
【发布时间】:2013-05-23 07:44:10
【问题描述】:

我正在尝试将额外的 XML 文件添加到发布过程中。我有一个 MVC API 项目,它还有另一个用于控制器的项目(V1.0)。我们正在使用为每个项目创建 .XML 文件的自我记录帮助功能。在本地机器上构建时,一切正常,但发布(使用向导)时,它不会包含此文件。

我一直在尝试更新发布配置文件 (.pubxml) 文件,如下所述:

http://www.asp.net/mvc/tutorials/deployment/visual-studio-web-deployment/deploying-extra-files

但没有成功。我可以看到正在发生以下情况:

  • 我会打扫卫生以确保没有任何东西在附近徘徊。
  • 我使用向导发布
  • 我可以在 apiproject\bin\ 中看到所有文件,包括 apiprojectv1 xml 和 dll 文件
  • 我可以在 apiproject\obj\x86\Release\AspnetCompileMerge\Source\bin 中看到它有 apiprojectv1 dll 但没有 xml 文件
  • 我可以在 apiprojet\obj\x86\Release\AspnetCompileMerge\TempBuildDir\bin 中看到与上面相同的内容
  • 我可以在 apiproject\obj\x86\Release\Package\PackageTmp\bin 中看到与上面相同的内容

我不确定为什么没有复制文件。这是我的完整 pubxml 文件:

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize     the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit     http://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0"     xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <SiteUrlToLaunchAfterPublish />
    <publishUrl>\\myserver\wwwroot\apiproject</publishUrl>
    <DeleteExistingFiles>False</DeleteExistingFiles>
  </PropertyGroup>
  <Target Name="CustomCollectFiles">
        <ItemGroup>
          <_CustomFiles Include="..\bin\apiprojectv1.XML" />
          <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
            <DestinationRelativePath>%(RecursiveDir)%(Filename)%(Extension)    </DestinationRelativePath>
          </FilesForPackagingFromProject>
        </ItemGroup>
  </Target>
</Project>

编辑

我忘记了一个主要部分,将以下内容放在 pubxml 文件的底部:

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

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

我没有得到文件,但现在得到一个关于找不到文件的错误,(我现在可以调试)。

【问题讨论】:

    标签: c# asp.net-mvc msbuild publishing


    【解决方案1】:

    我错过了两件事:

    1. 实际告诉它执行操作的第二个属性组。
    2. 路径不对,必须使用项目目录路径

    现在看起来像这样并且可以工作:

    <?xml version="1.0" encoding="utf-8"?>
    <!--
    This file is used by the publish/package process of your Web project. You can customize the behavior of this process
    by editing this MSBuild file. In order to learn more about this please visit     http://go.microsoft.com/fwlink/?LinkID=208121. 
    -->
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <WebPublishMethod>FileSystem</WebPublishMethod>
        <SiteUrlToLaunchAfterPublish />
            <publishUrl>\\myserver\wwwroot\apiproject</publishUrl>
        <DeleteExistingFiles>False</DeleteExistingFiles>
      </PropertyGroup>
    
     <Target Name="CustomCollectFiles">
        <ItemGroup>
          <_CustomFiles Include="$(MSBuildProjectDirectory)\bin\apiprojectv1.XML" />
          <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
            <DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)    </DestinationRelativePath>
          </FilesForPackagingFromProject>
        </ItemGroup>
      </Target>
    
      <PropertyGroup>
        <CopyAllFilesToSingleFolderForPackageDependsOn>
          CustomCollectFiles;
          $(CopyAllFilesToSingleFolderForPackageDependsOn);
        </CopyAllFilesToSingleFolderForPackageDependsOn>
    
        <CopyAllFilesToSingleFolderForMsdeployDependsOn>
          CustomCollectFiles;
          $(CopyAllFilesToSingleFolderForPackageDependsOn);
        </CopyAllFilesToSingleFolderForMsdeployDependsOn>
    </PropertyGroup>
    
    </Project>
    

    【讨论】:

    • 很好,我正在寻找这个确切的解决方案,这成功了,谢谢!
    • 谢谢您,您的解决方案对我有用,包括由 c++ 项目生成的 dll,而该 dll 无法在普通 .net 项目中引用!
    • 我无法让它工作。我什至尝试过绝对 Windows 路径,但它不起作用。
    猜你喜欢
    • 1970-01-01
    • 2021-12-01
    • 1970-01-01
    • 2020-11-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多