向发布的MVC API项目添加额外的文件
本文关键字:添加 文件 项目 API MVC | 更新日期: 2023-09-27 18:15:45
我试图在发布过程中添加一个额外的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文件
- 我可以在apiproject '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>
我没有得到文件,但是现在得到一个关于没有找到文件的错误,(我现在可以调试)。
我错过了两件事:
- 第二个告诉它执行动作的属性组。
- 路径不正确,必须使用项目目录路径
现在看起来像这样,并工作:
<?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>