Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6000611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:43:06+00:00 2026-05-23T00:43:06+00:00

I’m trying to do speed up our build (csharp, msbuild, .net 3.5). Replace copy

  • 0

I’m trying to do speed up our build (csharp, msbuild, .net 3.5). Replace copy with fsutil hardlink create.

Previously, I almost got it with running a script over sln files and making the dll references private = false, then having a post build event create the hardlinks. Problem is transitive dependencies are not included. So, I think I need to reference the ResolveAssemblyReference task in msbuild to get the transitive dependencies I need to hardlink.

Any ideas?

This person tried the same thing, but did not post an final solution.

To be clear: What I want is to keep separate bin directories, but instead of copying file from one to another to create a hard link from a source (of a reference or a dependency) to the destination (the current project’s bin). Which is much faster, and gives approximately the same effect as copying.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:43:07+00:00Added an answer on May 23, 2026 at 12:43 am

    This is supported in VS 2010. But not 2008. See the UseHardLinksIfPossible option to Copy in _CopyFilesMarkedCopyLocal.

    See also http://social.msdn.microsoft.com/Forums/en/tfsbuild/thread/9382a3d8-4632-4826-ad15-d5e845080981, http://msdn.microsoft.com/en-us/library/ms171466(v=VS.90).aspx for context.

    Override the _CopyFilesMarkedCopyLocal target. We add something like this to the csproj files at the bottom: <Import Project="..\..\..\..\..\\CommonBuild\TW.Override.Microsoft.Common.targets" /> (This is auto added to the file with a nant task on every full nant build, so every project benefits).

    Our new targets file is:

    <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
         <UsingTask TaskName="CopyWithHardlinkOption" AssemblyFile="..\lib\TWBuildOptimization\TW.Hardlinker.dll" />
      <!--
        ============================================================
                                            _CopyFilesMarkedCopyLocal
        Overridden in order to allow hardlinking with our custom Copy Task.                                         
    
        Hardlinking is a major performance improvement. Sometimes 50% of the time compared to copying.
    
        Copy references that are marked as "CopyLocal" and their dependencies, including .pdbs, .xmls and satellites.
        ============================================================
      -->
        <Target
            Name="_CopyFilesMarkedCopyLocal">
            <CopyWithHardlinkOption
                SourceFiles="@(ReferenceCopyLocalPaths)"
                DestinationFiles="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')"
                SkipUnchangedFiles="true"
                  UseHardlinksIfPossible="true"
                OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)">
                <Output TaskParameter="DestinationFiles" ItemName="FileWritesShareable"/>
            </CopyWithHardlinkOption>
        </Target>
    </Project>
    
    

    See the msbuild 4 Copy UseHardlinksIfPossible option. I backported that to 3.5 through decompiling and reimplementing. The relevant logic in CopyFileWithLogging was:

          // The port from 4.0's task that allows hardlinking
            bool hardlinkSucceeded = false;
            if (UseHardlinksIfPossible)
            {
                if (File.Exists(destinationFile))
                {
                    FileUtilities.DeleteNoThrow(destinationFile);
                }
                if (!TwNativeMethods.CreateHardLink(destinationFile, sourceFile, IntPtr.Zero))
                {
                    var win32Exception = new Win32Exception(Marshal.GetLastWin32Error());
                    Log.LogMessage(MessageImportance.High, "Hardlinking had a problem {0}, will retry copying. {1}", new object[] {win32Exception.Message, win32Exception});
                }
                hardlinkSucceeded = true;
            }
            if (!hardlinkSucceeded)
            {
                Log.LogMessageFromResources(MessageImportance.Normal, "Copy.FileComment", new object[] { sourceFile, destinationFile });
                Log.LogMessageFromResources(MessageImportance.Low, "Shared.ExecCommand", new object[0]);
                Log.LogCommandLine(MessageImportance.Low, "copy /y \"" + sourceFile + "\" \"" + destinationFile + "\"");
                File.Copy(sourceFile, destinationFile, true);
            }
            // end port
    

    Also had to add these:

    // decompiled from 4.0
    internal static class TwNativeMethods
    {
        [DllImport("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
        internal static extern bool CreateHardLink(string newFileName, string exitingFileName, IntPtr securityAttributes);
    }
    
    // decompiled from 4.0
    internal static class FileUtilities
    {
        internal static void DeleteNoThrow(string path)
        {
            try
            {
                File.Delete(path);
            }
            catch (Exception exception)
            {
                if (ExceptionHandling.NotExpectedException(exception))
                {
                    throw;
                }
            }
        }
    }
    
    // decompiled from 4.0
    internal static class ExceptionHandling
    {
        // Methods
        internal static bool IsCriticalException(Exception e)
        {
            return (((e is StackOverflowException) || (e is OutOfMemoryException)) || ((e is ExecutionEngineException) || (e is AccessViolationException)));
        }
    
        internal static bool NotExpectedException(Exception e)
        {
            return (((!(e is UnauthorizedAccessException) && !(e is ArgumentNullException)) && (!(e is PathTooLongException) && !(e is DirectoryNotFoundException))) && ((!(e is NotSupportedException) && !(e is ArgumentException)) && (!(e is SecurityException) && !(e is IOException))));
        }
    
        internal static bool NotExpectedReflectionException(Exception e)
        {
            return ((((!(e is TypeLoadException) && !(e is MethodAccessException)) && (!(e is MissingMethodException) && !(e is MemberAccessException))) && ((!(e is BadImageFormatException) && !(e is ReflectionTypeLoadException)) && (!(e is CustomAttributeFormatException) && !(e is TargetParameterCountException)))) && (((!(e is InvalidCastException) && !(e is AmbiguousMatchException)) && (!(e is InvalidFilterCriteriaException) && !(e is TargetException))) && (!(e is MissingFieldException) && NotExpectedException(e))));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
We're building an app, our first using Rails 3, and we're having to build
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.