Including files outside the project in MSBuild

I found other posts here on StackOverflow that relate to my problem I am having, for example:

MSBuild: Deploying files that are not included in the project , as well as Include files in MSBuild that are not part of the project. I wanted to share the code that I could create after reading these messages and ask for some help as to why it might not work?

Find out what exactly is 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 I would like to do this, and then take the files that it displays (it outputs them to my Includes / Javascript / Bundled folder) and includes them in the create part in MSBuild (so that they were deployed to the target IIS server).

When I edited my local .csproj in my local Visual Studio and added the code below to the end of the file and rebooted, I managed to right-click on my web project, select “publish”, and then select my local file-based publish profile, which really expanded my files in the right place. It worked!

Then I checked my code on TFS and switched to a “build” on TFS and queued up a new assembly. Of course, I was able to see how the files are output to the same directory on the build server. Now I'm not 100% sure of MSBuild, but I noticed that just as when I hit the publication locally, it also created the _publishedWebsite folder on the build server (the directory is above the source). The fact is that in this published website folder my manually created files were missing. Also, switching to the target web server after the build was completed, unfortunately, did not have the files I wanted.

So it seems that if I manually selected the publication, the code below would work, but if I stood in line with the assembly with TFS, it would not work. Does MSBuild use publishing? Could this be the reason why it does not work below?

Here is the code that I posted 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 was really stuck with this and wanted to ask for some help as to why the files might not work. I suspect that MSBuild does not use the publication and why does it work locally (because I choose the publication)?

Many thanks for your help

UPDATE Tried this in accordance with the comments below, but this time the files didn’t even appear (therefore, it seems they didn’t even complete the tasks now). Any idea why? I typed it 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 put it in my pubxml file and then do the actual publication, it works, but as far as I know, our process is simply to queue the assembly from TFS. Is it possible to connect to the above block of code when it simply queues up the assembly? Or do I need to publish?

+5
source share
2 answers

To make a publication from a TFS assembly, you need to add the following arguments

 /p:DeployOnBuild=true;PublishProfile=Release 

obviously using the PublishProfile proper name

+2
source

In VS2012, the target has been renamed from:

CopyAllFilesToSingleFolderForPackageDependsOn

in

CopyAllFilesToSingleFolderForMsdeployDependsOn

Update: Looks like above. The targets do not receive the call from the VS2012 chains, can you replace it with the call to the target "PipelineCollectFilesPhaseDependsOn"? That should fix it.

 <PropertyGroup> <PipelineCollectFilesPhaseDependsOn> CustomCollectFiles; $(PipelineCollectFilesPhaseDependsOn); </PipelineCollectFilesPhaseDependsOn> </PropertyGroup> 
+2
source

Source: https://habr.com/ru/post/1204003/


All Articles