title: Including files outside of the project in MSBuild
body: <p>I have found other posts here on StackOverflow that deal with my issue I am experiencing, for example:</p>
  
  <p><a href="https://stackoverflow.com/questions/12852236/msbuild-deploying-files-that-are-not-included-in-the-project">MSBuild: Deploying files that are not included in the project</a> as well as <a href="https://stackoverflow.com/questions/17238218/include-files-in-msbuild-that-are-not-part-of-project">Include Files in MSBuild that are not a part of the project</a>
  I wanted to share the code that I was able to create after reading these posts and ask for some help as to why it might not be working?</p>
  
  <p>To elaborate on what exactly is not wrong and what I intend to do. I am using Visual Studio 2012, and TFS 2012.</p>
  
  <p>I have a batch file called CreateMyFiles.bat, and what I would like to do is execute this and then take the files it outputs (it outputs them to my Includes/Javascript/Bundled folder) and include them in part of the build in MSBuild (so that they are deployed to the target IIS server).</p>
  
  <p>When I edited my local .csproj in my local Visual Studio and added the code below to the bottom of the file and reloaded, I was able to right click on my web projbect, select 'publish', and then select my local file-based publishing profile which did indeed deploy my files to the correct location. It worked!</p>
  
  <p>I then checked in my code to TFS, and went to 'builds' on TFS, and queued a new build. Sure enough, I was able to see the files output to the same directory on the build server. Now, i'm not 100% sure about MSBuild but I noticed that just like when I hit publish locally, it created a _publishedWebsite folder on the build server as well (a directory above the source). The thing is, within this publishedwebsite folder, my manually created files were not present. Furthermore, going to the target web server after the build was done unfortunately did not have the files I wanted.</p>
  
  <p>So it seems like if I were to manually select publish, the code below works, but if I were to queue a build with TFS, it does not work. Does MSBuild use publish? Could that be the reason it does not work below?</p>
  
  <p>Here is the code I've placed in my .csproj file:</p>
  
  <pre><code>&lt;Target Name="CustomCollectFiles"&gt;
      &lt;Exec Command="CreateMyFiles.bat" /&gt; &lt;!-- Generate Files --&gt;
      &lt;ItemGroup&gt;
         &lt;!-- Create an identity called _CustomFiles, and associate it to the files I created --&gt;
        &lt;_CustomFiles Include="Includes\JavaScript\Bundled\*" /&gt;
        &lt;FilesForPackagingFromProject Include="%(_CustomFiles.Identity)"&gt;
          &lt;DestinationRelativePath&gt;Includes\JavaScript\Bundled\*%(Filename)%(Extension)        &lt;/DestinationRelativePath&gt;
        &lt;/FilesForPackagingFromProject&gt;
      &lt;/ItemGroup&gt;
    &lt;/Target&gt;
  
   &lt;!-- Hook into the pipeline responsible for gathering files and tell it to add my files --&gt;
    &lt;PropertyGroup&gt;
      &lt;CopyAllFilesToSingleFolderForPackageDependsOn&gt;
        CustomCollectFiles;
        $(CopyAllFilesToSingleFolderForPackageDependsOn);
      &lt;/CopyAllFilesToSingleFolderForPackageDependsOn&gt;
  
      &lt;CopyAllFilesToSingleFolderForMsdeployDependsOn&gt;
         CustomCollectFiles;
        $(CopyAllFilesToSingleFolderForPackageDependsOn);
      &lt;/CopyAllFilesToSingleFolderForMsdeployDependsOn&gt;
    &lt;/PropertyGroup&gt;
  </code></pre>
  
  <p>I'm really stuck on this and wanted to ask for some help as to why the files might not be going. I suspect MSBuild doesn't use publish and that's why it works locally (because i'm selecting publish)?</p>
  
  <p>Thanks so much for your help</p>
  
  <p><strong>UPDATE</strong>
  Tried this as per comments below, but this time the files didn't even appear (so it seemed to not even run the tasks now). Any idea why? Did I type this right?</p>
  
  <pre><code>&lt;Target Name="CustomCollectFiles"&gt;
    &lt;Exec Command="CreateMyFiles.bat" /&gt;
  
     &lt;!-- Generate Files --&gt;
     &lt;ItemGroup&gt;
     &lt;!-- Create an identity called _CustomFiles, and associate it to the files I created --&gt;
        &lt;_CustomFiles Include="Includes\JavaScript\Bundled\*" /&gt;
       &lt;FilesForPackagingFromProject Include="%(_CustomFiles.Identity)"&gt;
         &lt;DestinationRelativePath&gt;Includes\JavaScript\Bundled\*%(Filename)%(Extension)         &lt;/DestinationRelativePath&gt;
       &lt;/FilesForPackagingFromProject&gt;
     &lt;/ItemGroup&gt;
   &lt;/Target&gt;
  
  &lt;!-- Hook into the pipeline responsible for gathering files and tell it to add my files --&gt;
  &lt;PropertyGroup&gt;
    &lt;PipelineCollectFilesPhaseDependsOn&gt;
      CustomCollectFiles;
      $(PipelineCollectFilesPhaseDependsOn);
    &lt;/PipelineCollectFilesPhaseDependsOn&gt;
  &lt;/PropertyGroup&gt;
  </code></pre>
  
  <p><strong>UPDATE 2</strong>
  When I take the above code, and place it into my pubxml file and then execute an actual publish, it works, but as far as I know our process is to just queue a build from TFS. Is it possible to hook into the above code block when simply queuing a build? Or do I need to publish?</p>