2

To copy files in different location after the build is published, I tried the following:

Editing the csproj file, and adding this code, copies the dlls to bin of the relative path.

<PropertyGroup>  
<CopyAllFilesToSingleFolderForPackageDependsOn>  
    CustomCollectFiles; 
    $(CopyAllFilesToSingleFolderForPackageDependsOn);  
    </CopyAllFilesToSingleFolderForPackageDependsOn>  
</PropertyGroup> 
<Target Name="CustomCollectFiles">
  <ItemGroup>
    <_CustomFiles Include="..\*project*\**\*.dll" />
    <FilesForPackagingFromProject  Include="%(_CustomFiles.Identity)">
      <DestinationRelativePath>bin\%(Filename)%(Extension)</DestinationRelativePath>
    </FilesForPackagingFromProject>
  </ItemGroup>
</Target>

This works absolutely fine. I was just wondering if this can be done using post build events something like this.. ( this doesnt work).

if $(ConfigurationName) == Release xcopy /y "$(ProjectDir)$(OutDir)$(TargetFileName)" "$(SolutionDir)$(OutDir)" 

Is the first way is the "only way of doing it" with oneclick publish in VS2010? The concern being, the changes in the csproj files will not be shown anywhere, in VS2010.

genericuser
  • 1,430
  • 4
  • 22
  • 40

2 Answers2

7

Yes, you can do it without hacking using AfterBuild target and Copy task:

  <Target Name="AfterBuild">
    <ItemGroup>
      <_CustomFiles Include="..\**\*.dll" />
    </ItemGroup>
      <Copy
            SourceFiles="@(_CustomFiles)"
            DestinationFiles="@(_CustomFiles->'bin\%(Filename)%(Extension)')" 
            SkipUnchangedFiles="true" />
  </Target>
Sergio Rykov
  • 4,176
  • 25
  • 23
  • Says exited with code 255. The bin folder is of other proj, and all its contents should be part of this proj while making the build. – genericuser Feb 11 '11 at 16:18
  • 3
    "Hacking" or CopyAllFilesToSingleFolderForPackageDependsOn is still necessary, if you want this to work with WebDeploy. I ended up using AfterBuild target for Debug configuration and CopyAllFilesToSingleFolderForPackageDependsOn for Nightly configuration which gets deployed automatically. – juhan_h Jul 09 '12 at 10:57
  • I agree with you. I can say it is a [recommended](http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx) way. But @Priya10 asked a bit different thing. – Sergio Rykov Jul 10 '12 at 08:10
  • In order to copy files in all publishing context, I found that you should also add a property node named 'CopyAllFilesToSingleFolderForMsdeployDependsOn' (i.e. with *Msdeploy* instead of *Package*). See [here](http://stackoverflow.com/questions/2747081/how-do-you-include-additional-files-using-vs2010-web-deployment-packages) – superjos Oct 13 '13 at 16:26
0

This will also work and is maintainable across different Visual Studio versions.

<Target Name="CustomFolderDeploy" AfterTargets="CopyAllFilesToSingleFolderForPackage" BeforeTargets="MSDeployPublish">
    <PropertyGroup>
      <CustomFolder>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\..\..\..\Lib\CustomFolder'))</CustomFolder>
    </PropertyGroup>
    <CreateItem Include="$(CustomFolder)\*.*">
      <Output TaskParameter="Include" ItemName="CustomFiles" />
    </CreateItem>
    <Copy SourceFiles="@(CustomFiles)" DestinationFolder="$(MSBuildProjectDirectory)\obj\$(Configuration)\Package\PackageTmp\bin" SkipUnchangedFiles="True" ContinueOnError="False" />
  </Target>
Ostati
  • 4,623
  • 3
  • 44
  • 48