Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding extra files to published MVC API project

Tags:

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).

like image 405
Jon Avatar asked May 28 '13 10:05

Jon


People also ask

Where are Pubxml files stored?

pubxml and are located in the PublishProfiles folder. The PublishProfiles folder is under Properties in a C# web application project, under My Project in a VB web application project, or under App_Data in a web site project.

How do I create a Pubxml file?

In order to create a new profile once you have already defined one, you have to open the "Publish" window (righ click on the project), click on the "Profile" tab and select the <New...> option from the drop-down list; this will create a new pubxml file (see screenshot).

How do I change the publish path in Visual Studio?

To specify a publishing location In the Publish Location field, enter the publishing location by using one of the following formats: To publish to a file share or disk path, enter the path by using either a UNC path (\\Server\ApplicationName) or a file path (C:\Deploy\ApplicationName).


1 Answers

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>
like image 98
Jon Avatar answered Oct 16 '22 00:10

Jon