파일 삭제를위한 MSBuild 작업 구문
프로덕션 빌드 스크립트의 bin 폴더에서 Obj 디렉터리와 PDB를 삭제하는 MSBuild 작업을 작성하려고하는데 제대로 작동하지 않는 것 같습니다.
누구든지이 작업을 수행하는 예제 또는 MSBuild를 사용하여 파일 및 디렉터리를 제거하는 간단한 예제에 대한 링크가 있습니까?
전체 디렉토리를 삭제하려면 RemoveDir 작업 이 필요합니다 .
<RemoveDir Directories="Path/To/Obj" />
bin에서 PDB 파일을 삭제하려면 삭제 작업 이 필요합니다 .
<Delete Files="Path/To/Bin/MyApp.pdb" />
삭제 작업에서는 와일드 카드를 사용할 수 없으므로 여러 pdb 파일이있는 경우 ItemGroup 을 인수로 제공해야합니다 .
먼저 해당 디렉토리의 파일을 삭제 한 다음 다음을 사용하여 디렉토리 자체를 삭제할 수 있습니다.
<Target Name="SomeTarget">
<ItemGroup>
<FilesToDelete Include="Path\To\Obj\**\*"/>
</ItemGroup>
<Delete Files="@(FilesToDelete)" />
<RemoveDir Directories="Path\To\Obj\" />
</Target>
내가 겪었던 동일한 문제에 부딪쳤을 수있는 다른 사람을 위해 게시합니다.
삭제 작업은 MSBuild가 TFS에서 최신 파일을 가져 오면 파일이 읽기 전용으로 표시되므로 할 수 있어야하는 읽기 전용 파일을 삭제할 수 없습니다. EXEC 명령을 사용하여 읽기 전용 파일을 삭제했습니다.
<ItemGroup>
<FileToDelete Include="c:\temp\fileToDelete.txt"/>
</ItemGroup>
<Exec Command="del /F /Q "@(FileToDelete)""/>
게시 된 답변은 단일 디렉토리를 처리해야하는 한 작동합니다. 중첩 된 폴더 RemoveDir가있는 경우 오류와 함께 실패 Directory not empty합니다.
약간 일반적인 접근 방식은 중첩 된 폴더도 처리합니다.
<Target Name="CleanOutDir">
<ItemGroup>
<FilesToClean Include="$(OutDir)\**\*.*" />
<!-- Bit of .Net to get all folders and subfolders -->
<FoldersToClean Include="$([System.IO.Directory]::GetDirectories("$(OutDir)"))" />
</ItemGroup>
<Delete Files="@(FilesToClean)"/>
<RemoveDir Directories="@(FoldersToClean)" />
</Target>
이 코드는 너무 추해서 비행기 멀미 가방과 함께 제공되어야합니다. ;-) 그러나 삭제할 파일 목록을 작성하지 않기 때문에 빠릅니다.
<Target Name="DeleteBuildFolder">
<Exec Command="RmDir /S /Q "$(BuildFolder)"" />
<Exec Command="RmDir /S /Q "$(BuildFolder)"" />
<Exec Command="RmDir /S /Q "$(BuildFolder)"" />
<Exec Command="RmDir /S /Q "$(BuildFolder)"" />
<Exec Command="RmDir /S /Q "$(BuildFolder)"" />
<Exec Command="RmDir /S /Q "$(BuildFolder)"" />
<Exec Command="RmDir /S /Q "$(BuildFolder)"" />
</Target>
몇 개의 RmDir 명령이 필요합니까? RmDir 명령 몇 개는 "디렉토리가 비어 있지 않습니다."대신 "지정된 파일을 찾을 수 없습니다"를 반환합니다. 내 컴퓨터에서 $ (BuildFolder)가 Windows 탐색기에서 열려 있으면 다른 RmDir을 사용하는 것 같습니다. 바이러스 백신 프로그램은 때때로 Subversion을 수행하는 것처럼 RmDir에 영향을 미칠 수 있지만 제외 목록을 (잘못) 관리하는 것보다 포괄적 인 AV 보호 기능을 사용하고 싶습니다.
먼저 파일에서 readonly 속성을 제거하고 msbuild 삭제 작업을 실행할 수도 있습니다.
이렇게 :
<Target Name="DeleteFiles">
<Message Text="Delete File" Importance="high"/>
<Attrib Files="$(FileToDelete)" ReadOnly="false" />
<Delete Files="$(FileToDelete)" />
</Target>`
Visual Studio 2013에서 </Project>닫는 태그 바로 앞의 .csproj 파일 끝에 이것을 추가했습니다.
<Target Name = "clean_folders" AfterTargets="Clean">
<Exec Command = "rd /S /Q obj" />
<Exec Command = "rd /S /Q bin" />
</Target>
At first it didn't appear to work but I noticed that Visual Studio (or R#, not sure) re-re-added DesignTimeResolveAssemblyReferencesInput.cache to the obj folder and it also re-added the current \bin folder (I have different builds in different subfolders under \bin). It cleaned away everything else, including the 25 other build configs I have from imported .csproj files (yes, I know).
Be careful if you Batch Rebuild more than one config as it just wipes all previous efforts on each rebuild leaving you with only the last one. Whups.
Just to add one more wrinkle that I've discovered. I'm using Visual Studio 2015. The posted answers that are deleting via wildcard are still troublesome for me. I suspect that the wildcards are evaluated before the build, not after. That means the deletions won't happen if the files you want to delete are created during the build. It also leads to wonderful behavior where the delete works every second time you build, which makes this all very enjoyable to test.
I'm giving up on wildcards. For what I'm doing I know the files that are causing trouble and I'm hard-coding (if it can be called that inside of a project file) the actual file names.
참고URL : https://stackoverflow.com/questions/1478644/msbuild-task-syntax-for-deleting-files
'IT TIP' 카테고리의 다른 글
| 여러 dex 파일이 Lorg / apache / cordova / BuildHelper를 정의합니다. (0) | 2020.10.30 |
|---|---|
| 레일스 콘솔이 libreadline으로 인해로드되지 않습니다. (0) | 2020.10.30 |
| 두 변수의 값을 바꾸는 PHP 함수가 있습니까? (0) | 2020.10.30 |
| Ruby gem mysql2 설치 실패 (0) | 2020.10.30 |
| 투명한 배경으로 UITableViewCell을 만드는 방법 (0) | 2020.10.30 |