adding extra files to published MVC API project
Asked Answered
A

1

20

I am trying to add an extra XML file to a publishing process. I have a MVC API project which also has another project (V1.0) for controllers. We are using the self documenting help functionality which creates the .XML files for each project. When building on the local machine it all works but when publishing (with wizard) it will not include this file.

I have been trying to update the publish profile (.pubxml) file as described here:

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

but without success. I can see the following is happening:

  • I do a clean to ensure nothing hanging around.
  • I publish with wizard
  • I can see in apiproject\bin\ there are all the files including the apiprojectv1 xml and dll files
  • I can see in apiproject\obj\x86\Release\AspnetCompileMerge\Source\bin it has the apiprojectv1 dll but not the xml file
  • I can see the same as above in apiprojet\obj\x86\Release\AspnetCompileMerge\TempBuildDir\bin
  • I can see the same as above in apiproject\obj\x86\Release\Package\PackageTmp\bin

I am not sure why the file is not being copied across. This is my full pubxml file:

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

EDIT

I had forgot one major part, to put the below at the bottom of the pubxml file:

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

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

I do not get the file, but now get an error regarding the file not being found, (which I can now debug).

Asbury answered 28/5, 2013 at 10:57 Comment(0)
A
28

I had missed two things:

  1. The second property group to actually tell it to perform the action.
  2. The path was not right, had to use project directory path

Now looks like this and works:

<?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>
Asbury answered 28/5, 2013 at 15:34 Comment(3)
Nice, I was looking for this exact solution and this did the trick, thanks!Luong
Thank you, your solution worked for me to include a dll generated by a c++ project that can't be referenced in a normal .net project!Reimport
I can't get this to work. I even tried absolute windows path but it does not work.Drayage

© 2022 - 2024 — McMap. All rights reserved.