5

I have found other posts here on StackOverflow that deal with my issue I am experiencing, for example:

MSBuild: Deploying files that are not included in the project as well as Include Files in MSBuild that are not a part of the project 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?

To elaborate on what exactly is not wrong and what I intend to do. I am using Visual Studio 2012, and TFS 2012.

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

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!

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.

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?

Here is the code I've placed in my .csproj file:

<Target Name="CustomCollectFiles">
    <Exec Command="CreateMyFiles.bat" /> <!-- Generate Files -->
    <ItemGroup>
       <!-- Create an identity called _CustomFiles, and associate it to the files I created -->
      <_CustomFiles Include="Includes\JavaScript\Bundled\*" />
      <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
        <DestinationRelativePath>Includes\JavaScript\Bundled\*%(Filename)%(Extension)        </DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>

 <!-- Hook into the pipeline responsible for gathering files and tell it to add my files -->
  <PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForPackageDependsOn>

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

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

Thanks so much for your help

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

<Target Name="CustomCollectFiles">
  <Exec Command="CreateMyFiles.bat" />

   <!-- Generate Files -->
   <ItemGroup>
   <!-- Create an identity called _CustomFiles, and associate it to the files I created -->
      <_CustomFiles Include="Includes\JavaScript\Bundled\*" />
     <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
       <DestinationRelativePath>Includes\JavaScript\Bundled\*%(Filename)%(Extension)         </DestinationRelativePath>
     </FilesForPackagingFromProject>
   </ItemGroup>
 </Target>

<!-- Hook into the pipeline responsible for gathering files and tell it to add my files -->
<PropertyGroup>
  <PipelineCollectFilesPhaseDependsOn>
    CustomCollectFiles;
    $(PipelineCollectFilesPhaseDependsOn);
  </PipelineCollectFilesPhaseDependsOn>
</PropertyGroup>

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

Community
  • 1
  • 1
NullHypothesis
  • 4,286
  • 6
  • 37
  • 79

2 Answers2

2

In VS2012, the target was renamed from:

CopyAllFilesToSingleFolderForPackageDependsOn

to:

CopyAllFilesToSingleFolderForMsdeployDependsOn

Update: looks like the above Targets are not getting called from within VS2012 targets, can you replace it with a call to the Target "PipelineCollectFilesPhaseDependsOn"? That should fix it.

<PropertyGroup>
    <PipelineCollectFilesPhaseDependsOn>
      CustomCollectFiles;
      $(PipelineCollectFilesPhaseDependsOn);
      </PipelineCollectFilesPhaseDependsOn>    
</PropertyGroup>
Isaiah4110
  • 9,855
  • 1
  • 40
  • 56
  • Yes that's true, thanks, although if you look I actually do indeed have that below it (so I have both). Is that OK or do you think it would create problems? It doesn't throw any errors regarding compilation or saving project. thanks for your help:) – NullHypothesis Oct 04 '14 at 15:31
  • No dice - I updated above - any chance you could let me know your thoughts? thanks for your support! – NullHypothesis Oct 04 '14 at 16:13
  • Does MSBUILD do a deploy or a publish? Should I just xcopy everything to the target server? – NullHypothesis Oct 04 '14 at 16:36
2

to do a publish from TFS build you need to add the following arguments

/p:DeployOnBuild=true;PublishProfile=Release

obviously using your own PublishProfile name

Just TFS
  • 4,697
  • 1
  • 18
  • 22
  • So when I queue a build in TFS, it does *NOT* execute a publish? Is there any way that I could run the above code without having to publish? – NullHypothesis Oct 07 '14 at 13:52
  • no no publish unless you tell it to with the MSBuild Args shown Above. you could do something similar, but your code above is targetted at the publishing i assume due to "FilesForPackagingFromProject" being in the code – Just TFS Oct 07 '14 at 14:14
  • Thanks so what I think is happening is that when I queue, i'm seeing the files get pushed to the publishing target simply because of the ms build activity, right? Is there any harm in also publishing? – NullHypothesis Oct 07 '14 at 14:20
  • wouldn't have thought so – Just TFS Oct 07 '14 at 14:26
  • ok let me try the switch and see what happens, thanks. I'll return soon and let you know and will not forget to mark answered :) – NullHypothesis Oct 07 '14 at 14:27
  • So publish ended up breaking the site CS0246: The type or namespace name 'ProfileCommon' could not be found (are you missing a using directive or an assembly reference?) I am not sure why it would do that but I had to delete the whole site and place a backup in place to get it back. – NullHypothesis Oct 07 '14 at 20:17
  • this ended up helping me to arrive at a conclusion thank you. The PublishProfile and DeployOnBuild were necessary to get the events to get wired up correctly. Without the above, most of the events I tried did not work! – NullHypothesis Oct 14 '14 at 12:46