开发者

copy files in different location after the build

开发者 https://www.devze.com 2023-02-10 04:05 出处:网络
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.

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> 
<Tar开发者_如何学运维get 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.


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>


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号