0

I am using msbuild script to deploy ssrs reports. Previously all reports used to be in one folder and I have written a msbuild script to deploy these reports to report server. Now we are maintaining reports at folder level such as customer service, inventory and invoice folders.

How to deploy these individual folder to report server? In report server also we need folder level hierarchy.

thor
  • 21,418
  • 31
  • 87
  • 173
  • It's hard to help if you don't provide more information. What do you have in place (Script)? What is the problem you want to resolve? With MsBuild you can work with Full paths, relative paths, wildcards, recursive directories, etc. Be more specific. – Rolo May 05 '16 at 12:38

2 Answers2

0

Were you using the msbuild Copy task to do your single folder copy? If so, it shouldn't be a big deal to modify that same task just a bit to copy the entire folder structure. Something similar to this example:

<Copy SourceFiles="c:\src\**\*.txt" DestinationFolder="c:\dest\%(RecursiveDir)"></Copy>

%(RecursiveDir) is a type of well-known item metadata that will contain the value of the wildcard from the source files parameter. Here's a bit more description of MSBuild well-known item metadata:

MSBuild well known item metadata


Complete Example:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Sources Include="c:\src\**\*.txt" />
  </ItemGroup>
  <Target Name="copy-folder">
    <Copy SourceFiles="@(Sources)" DestinationFolder="c:\dest\%(RecursiveDir)"></Copy>
  </Target>
</Project>
xianwill
  • 523
  • 3
  • 9
  • Here i am getting folder name as "Inventory\" how to get rid of the "\" from output? – Mahesh kumar Chiliveri May 05 '16 at 11:40
  • Not sure why you would be getting a trailing slash. If you edit your question and describe your folder structure and exact msbuild script, it will be easier to help. -- I did edit my answer to show a complete example that easily accomplishes a recursive copy for me. – xianwill May 07 '16 at 03:06
0

Here is a recursive file copy example.

Save the below in a file called "FileCopyRecursive.msbuild" (or FileCopyRecursive.proj)

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped">

    <PropertyGroup>
        <!-- Always declare some kind of "base directory" and then work off of that in the majority of cases  -->
        <WorkingCheckout>.</WorkingCheckout>
        <WindowsSystem32Directory>c:\windows\System32</WindowsSystem32Directory>
        <ArtifactDestinationFolder>$(WorkingCheckout)\ZZZArtifacts</ArtifactDestinationFolder>
    </PropertyGroup>

    <Target Name="AllTargetsWrapped">

        <CallTarget Targets="CleanArtifactFolder" />
        <CallTarget Targets="CopyFilesToArtifactFolder" />
    </Target>

    <Target Name="CleanArtifactFolder">

        <RemoveDir Directories="$(ArtifactDestinationFolder)" Condition="Exists($(ArtifactDestinationFolder))"/>
        <MakeDir Directories="$(ArtifactDestinationFolder)" Condition="!Exists($(ArtifactDestinationFolder))"/>
        <RemoveDir Directories="$(ZipArtifactDestinationFolder)" Condition="Exists($(ZipArtifactDestinationFolder))"/>
        <MakeDir Directories="$(ZipArtifactDestinationFolder)" Condition="!Exists($(ZipArtifactDestinationFolder))"/>               
        <Message Text="Cleaning done" />
    </Target>

    <Target Name="CopyFilesToArtifactFolder">

        <ItemGroup>
            <MyExcludeFiles Include="$(WindowsSystem32Directory)\**\*.doesnotexist" />
        </ItemGroup>

        <ItemGroup>
            <MyIncludeFiles Include="$(WindowsSystem32Directory)\**\*.ini" Exclude="@(MyExcludeFiles)"/>
        </ItemGroup>        

        <Copy
                SourceFiles="@(MyIncludeFiles)"
                DestinationFiles="@(MyIncludeFiles->'$(ArtifactDestinationFolder)\%(RecursiveDir)%(Filename)%(Extension)')"
        />

        </Target>

    </Project>

Then run this:

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" /target:AllTargetsWrapped FileCopyRecursive.msbuild /l:FileLogger,Microsoft.Build.Engine;logfile=AllTargetsWrapped.log

BONUS!

Here is a "fun with files" msbuild file.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="AllTargetsWrapper" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <Target Name="AllTargetsWrapper">
        <CallTarget Targets="FunWithFilesTask" />
    </Target>

    <PropertyGroup>
        <WorkingCheckout>c:\windows\System32</WorkingCheckout>
    </PropertyGroup>

    <!--    =====================================================                      -->

    <!--
        See:
        http://msdn.microsoft.com/en-us/library/ms164313.aspx

        *Identity    Value for the item specified in the Include attribute.
        *Filename   Filename for this item, not including the extension.
        *Extension  File extension for this item.
        *FullPath   Full path of this item including the filename.
        *RelativeDir    Path to this item relative to the current working directory.
        *RootDir    Root directory to which this item belongs.
        RecursiveDir    Used for items that were created using wildcards. This would be the directory that replaces the wildcard(s) statements that determine the directory.
        *Directory  The directory of this item.
        AccessedTime    Last time this item was accessed.
        CreatedTime     Time the item was created.
        ModifiedTime    Time this item was modified.   

    -->


    <Target Name="FunWithFilesTask">

        <ItemGroup>
            <MyExcludeFiles Include="$(WorkingCheckout)\**\*.doesnotexist" />
        </ItemGroup>

        <ItemGroup>
            <MyIncludeFiles Include="$(WorkingCheckout)\**\*.ini" Exclude="@(MyExcludeFiles)" />
        </ItemGroup>  

        <PropertyGroup>
            <MySuperLongString>@(MyIncludeFiles->'&quot;%(fullpath)&quot;')</MySuperLongString>
        </PropertyGroup>  

        <Message Text="MySuperLongString=$(MySuperLongString)"/>
        <Message Text="   "/>
        <Message Text="   "/>

        <Message Text="The below items are good when you need to feed command line tools, like the console NUnit exe.  Quotes around the filenames help with paths that have spaces in them. "/>
        <Message Text="I found this method initially from : http://pscross.com/Blog/post/2009/02/22/MSBuild-reminders.aspx       Thanks Pscross! "/>
        <Message Text="   "/>
        <Message Text="   "/>

        <Message Text="Flat list, each file surrounded by quotes, with semi colon delimiter: "/>
        <Message Text="          @(MyIncludeFiles->'&quot;%(fullpath)&quot;')"/>
        <Message Text="   "/>
        <Message Text="   "/>

        <Message Text="Flat list, each file surrounded by quotes, no comma (space delimiter): "/>
        <Message Text="          @(MyIncludeFiles->'&quot;%(fullpath)&quot;' , ' ')"/>
        <Message Text="   "/>
        <Message Text="   "/>

        <Message Text="Flat list, each file surrounded by quotes, with comma delimiter: "/>
        <Message Text="          @(MyIncludeFiles->'&quot;%(fullpath)&quot;' , ',')"/>
        <Message Text="   "/>
        <Message Text="   "/>

        <Message Text="List of files using special characters (carriage return)"/>
        <Message Text="@(MyIncludeFiles->'&quot;%(fullpath)&quot;' , '%0D%0A')"/>
        <Message Text="   "/>
        <Message Text="   "/>

    </Target>

</Project>
granadaCoder
  • 26,328
  • 10
  • 113
  • 146