如何使用Msbuild处理文件夹?

时间:2016-05-05 09:38:43

标签: reporting-services msbuild ssrs-2008-r2

我正在使用msbuild脚本来部署ssrs个报告。以前所有报告都在一个文件夹中,我编写了一个msbuild脚本来将这些报告部署到报告服务器。现在,我们正在维护文件夹级别的报告,例如customer service, inventoryinvoice文件夹。

如何将这些个人文件夹部署到报表服务器?在报表服务器中,我们还需要文件夹级别。

2 个答案:

答案 0 :(得分:0)

您是否使用msbuild Copy任务执行单个文件夹复制?如果是这样,修改同一个任务只是为了复制整个文件夹结构应该不是什么大不了的事。类似于这个例子的东西:

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

%(RecursiveDir)是一种众所周知的项元数据,它将包含源文件参数中通配符的值。这里有MSBuild众所周知的项元数据的更多描述:

MSBuild well known item metadata

完整示例:

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

答案 1 :(得分:0)

这是一个递归文件复制示例。

将以下内容保存在名为&#34; FileCopyRecursive.msbuild&#34;的文件中。 (或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>

然后运行:

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

奖金!

这是一个有趣的文件&#34; msbuild文件。

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