2016-05-05 3 views
0

Я использую сценарий msbuild для развертывания ssrs отчетов. Раньше все отчеты были в одной папке, и я написал сценарий msbuild для развертывания этих отчетов для сервера отчетов. Теперь мы поддерживаем отчеты на уровне папок, такие как customer service, inventory и invoice папок.Как работать с папками с помощью Msbuild?

Как развернуть эту отдельную папку для сервера отчетов? В сервере отчетов также нужна иерархия уровней папок.

+0

Трудно помочь, если вы не предоставите больше информации. Что у вас на месте (сценарий)? В чем проблема, которую вы хотите решить? С MsBuild вы можете работать с полными путями, относительными путями, подстановочными знаками, рекурсивными каталогами и т. Д. Будьте более конкретными. – Rolo

ответ

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

Здесь я получаю имя папки как «Инвентарь», как избавиться от «\» с вывода? –

+0

Не знаете, почему вы получите конечную косую черту. Если вы отредактируете свой вопрос и опишите структуру папок и точный скрипт msbuild, вам будет легче помочь. - Я отредактировал свой ответ, чтобы показать полный пример, который легко выполняет рекурсивную копию для меня. – xianwill

0

Вот рекурсивный пример копирования файлов.

Сохранить ниже в файле под названием "FileCopyRecursive.msbuild" (или 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 

БОНУС!

Это файл msbuild "fun with files".

<?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> 
Смежные вопросы