Microsoft MVP성태의 닷넷 이야기
오류 유형: 902. Visual Studio - error MSB3021: Unable to copy file [링크 복사], [링크+제목 복사],
조회: 9227
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

Visual Studio - error MSB3021: Unable to copy file

Visual Studio에서 csproj의 ItemGroup/Content를 이용한 파일 복사를 하다 보면,

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="IronPython" Version="3.4.1" />
        <PackageReference Include="IronPython.StdLib" Version="3.4.1" />
    </ItemGroup>

    <ItemGroup>
        <Content Include="C:\Python310\**">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
    </ItemGroup>

    <ItemGroup>
        <None Update="test.py">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
    </ItemGroup>

</Project>

경우에 따라 이런 복사 오류가 발생할 수 있습니다

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5254,5): error MSB3021: Unable to copy file "C:\Python312\tensorflow\python\Lib\site-packages\tensorflow\include\tensorflow\compiler\xla\mlir_hlo\_virtual_includes\shape_component_analysis\mhlo\analysis\shape_component_analysis.h" to "bin\Debug\net8.0\python\Lib\site-packages\tensorflow\include\tensorflow\compiler\xla\mlir_hlo\_virtual_includes\shape_component_analysis\mhlo\analysis\shape_component_analysis.h". Could not find a part of the path 'bin\Debug\net8.0\python\Lib\site-packages\tensorflow\include\tensorflow\compiler\xla\mlir_hlo\_virtual_includes\shape_component_analysis\mhlo\analysis\shape_component_analysis.h'.


메시지에 포함된 "Could not find a part of the path" 문구가 다소 혼란스러운데요, 물론 경로를 찾지 못한 상황에서도 발생할 수 있겠지만 위와 같은 경우에는 경로가 너무 길어서 발생하는 문제입니다.

재미있는 건, 해당 문제는 비주얼 스튜디오와 MSBuild로 빌드할 때만 발생한다는 점입니다. 반면 dotnet으로 직접 빌드하면 오류 없이 잘 복사가 됩니다. ^^;

이상하군요, 원래 dotnet은 내부적으로 MSBuild를 호출하는 것으로 아는데... 어쨌든, 현상이 저렇게 나옵니다.




만약 명령행으로 빌드하는 경우라면, 그냥 msbuild에서 dotnet으로 변경하면 되겠지만 문제는 비주얼 스튜디오에서 빌드 시 저런 문제가 발생한다는 점입니다.

이런 경우 문제 해결이 아닌, 우회 해법으로 그냥 경로가 너무 길지 않도록 OutputPath를 지정하는 방법이 있습니다.

<Project Sdk="Microsoft.NET.Sdk">
    <!-- 생략 -->

    <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
        <OutputPath>c:\temp\Console</OutputPath>
    </PropertyGroup>
</Project>

msbuild ConsoleApp3.csproj -p:Configuration=Debug

또는, Windows 10 이상의 운영체제라면 깔끔하게 레지스트리 설정을 통해 제약을 없앨 수 있습니다.

Enable Long Paths in Windows 10, Version 1607, and Later
; https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry
; https://www.backupery.com/how-to-enable-ntfs-long-paths-in-windows/

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"LongPathsEnabled"=dword:00000001

(과거 버전은 어땠는지 모르겠지만) 현재의 Windows 11 환경에서는 재부팅 필요 없이 바로 반영돼 오류 없이 빌드할 수 있습니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 4/30/2024]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 46  47  48  49  [50]  51  52  53  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12685정성태6/21/202118100Java: 21. Azure Web App Service에 배포된 Java 프로세스의 메모리 및 힙(Heap) 덤프 뜨는 방법
12684정성태6/19/202116439오류 유형: 728. Visual Studio 2022부터 DTE.get_Properties 속성 접근 시 System.MissingMethodException 예외 발생
12683정성태6/18/202117757VS.NET IDE: 166. Visual Studio 2022 - Windows Forms 프로젝트의 x86 DLL 컨트롤이 Designer에서 오류가 발생하는 문제 [1]파일 다운로드1
12682정성태6/18/202114310VS.NET IDE: 165. Visual Studio 2022를 위한 Extension 마이그레이션
12681정성태6/18/202114570오류 유형: 727. .NET 2.0 ~ 3.5 + x64 환경에서 System.EnterpriseServices 참조 시 CS8012 경고
12680정성태6/18/202116610오류 유형: 726. python2.7.exe 실행 시 0xc000007b 오류
12679정성태6/18/202116755COM 개체 관련: 23. CoInitializeSecurity의 전역 설정을 재정의하는 CoSetProxyBlanket 함수 사용법파일 다운로드1
12678정성태6/17/202115263.NET Framework: 1072. C# - CoCreateInstance 관련 Inteop 오류 정리파일 다운로드1
12677정성태6/17/202118043VC++: 144. 역공학을 통한 lxssmanager.dll의 ILxssSession 사용법 분석파일 다운로드1
12676정성태6/16/202117226VC++: 143. ionescu007/lxss github repo에 공개된 lxssmanager.dll의 CLSID_LxssUserSession/IID_ILxssSession 사용법파일 다운로드1
12675정성태6/16/202115099Java: 20. maven package 명령어 결과물로 (war가 아닌) jar 생성 방법
12674정성태6/15/202116369VC++: 142. DEFINE_GUID 사용법
12673정성태6/15/202116972Java: 19. IntelliJ - 자바(Java)로 만드는 Web App을 Tomcat에서 실행하는 방법
12672정성태6/15/202118570오류 유형: 725. IntelliJ에서 Java webapp 실행 시 "Address localhost:1099 is already in use" 오류
12671정성태6/15/202127241오류 유형: 724. Tomcat 실행 시 Failed to initialize connector [Connector[HTTP/1.1-8080]] 오류
12670정성태6/13/202117219.NET Framework: 1071. DLL Surrogate를 이용한 Out-of-process COM 개체에서의 CoInitializeSecurity 문제파일 다운로드1
12669정성태6/11/202117400.NET Framework: 1070. 사용자 정의 GetHashCode 메서드 구현은 C# 9.0의 record 또는 리팩터링에 맡기세요.
12668정성태6/11/202119912.NET Framework: 1069. C# - DLL Surrogate를 이용한 Out-of-process COM 개체 제작파일 다운로드2
12667정성태6/10/202117722.NET Framework: 1068. COM+ 서버 응용 프로그램을 이용해 CoInitializeSecurity 제약 해결파일 다운로드1
12666정성태6/10/202115348.NET Framework: 1067. 별도 DLL에 포함된 타입을 STAThread Main 메서드에서 사용하는 경우 CoInitializeSecurity 자동 호출파일 다운로드1
12665정성태6/9/202117406.NET Framework: 1066. Wslhub.Sdk 사용으로 알아보는 CoInitializeSecurity 사용 제약파일 다운로드1
12664정성태6/9/202115175오류 유형: 723. COM+ PIA 참조 시 "This operation failed because the QueryInterface call on the COM component" 오류
12663정성태6/9/202117608.NET Framework: 1065. Windows Forms - 속성 창의 디자인 설정 지원: 문자열 목록 내에서 항목을 선택하는 TypeConverter 제작파일 다운로드1
12662정성태6/8/202115359.NET Framework: 1064. C# COM 개체를 PIA(Primary Interop Assembly)로써 "Embed Interop Types" 참조하는 방법파일 다운로드1
12661정성태6/4/202127348.NET Framework: 1063. C# - MQTT를 이용한 클라이언트/서버(Broker) 통신 예제 [4]파일 다운로드1
12660정성태6/3/202118079.NET Framework: 1062. Windows Forms - 폼 내에서 발생하는 마우스 이벤트를 자식 컨트롤 영역에 상관없이 수신하는 방법 [1]파일 다운로드1
... 46  47  48  49  [50]  51  52  53  54  55  56  57  58  59  60  ...