Search code examples
visual-studiodeploymentmercurialpublishorchardcms

Visual Studio publish (deployment) package contains Mercurial (hg) files (Orchard)


I have a C# solution for a web project (actually it's an Orchard CMS site, but this is not important) that's version controlled under Mercurial (using Tortoise HG BTW), which has some projects that are in separate repositories (and are subrepositories of the solution repository). Hg files are never included anywhere in the solution, they are nowhere shown in Visual Studio.

When I try to publish the solution (or build the deployment package) with the "Only files needed to run the application" option selected under the web project properties the package built contains the hg files (like the whole .hg folder) of the subrepositories.

This is mostly harmless (besides publishing a bunch of unnecessary files), but publishing can also fail completely with the following message:

Error Copying file SubRepoFolder.hg\store\data_libraries_parallel_extensions_extras_coordination_data_structures_async_coordination_async_reader_writer.cs.i to obj\Release\Package\PackageTmp\SubRepoFolder.hg\store\data_libraries_parallel_extensions_extras_coordination_data_structures_async_coordination_async_reader_writer.cs.i failed. The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

I have no idea what to do next, how to prevent VS from building files that it supposedly doesn't see. Any help would be greatly appreciated.


Solution

  • It turns out the fact that this is an Orchard solution is an important fact!

    There's this line in Orchard.Web.csproj:

    <Target Name="CustomCollectFiles">
    <ItemGroup>
      ...
      <_CustomFiles Include="Media\**\*;App_Data\**\*;Modules\**\*;Themes\**\*;Core\**\*" Exclude="**\obj\**;@(Orchard-Web-Bins -> '**\%(Filename)%(Extension)');**\*.csproj.user;**\*.hg*" />
    

    It's used to copy files from Orchard-specific folders to the build package. Notice that it's supposed to exlude Mercurial files and folders, but it isn't. I changed the line to this:

    <_CustomFiles Include="Media\**\*;App_Data\**\*;Modules\**\*;Themes\**\*;Core\**\*" Exclude="**\obj\**;@(Orchard-Web-Bins -> '**\%(Filename)%(Extension)');**\*.csproj.user;**\.hg\**" />
    

    Note the "*" after .hg. Yes, this took me approximately three hours, walking through every build config option I could find to arrive at this.

    Now this only excludes .hg folders, but not .hg files (like .hgignore or .htags) but I don't care: those are harmless in contrary to the .hg folders that include a bunch of files.

    This blogpost helped me.