Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 

dotnet publish - error NETSDK1047: Assets file '...\obj\project.assets.json' doesn't have a target for '...'

다양한 상황에서 이런 오류가 나올 수 있겠지만, 제 경우에는 .NET Core 3.x 이하의 프로젝트를 빌드할 때였습니다. 문제의 원인은, 동일한 디렉터리를 공유하면서 먼저 Linux용으로 빌드한 후, 윈도우용으로 빌드할 때 발생했는데요, 일례로 다음과 같이 먼저 빌드를 한 다음,

docker build -t net3_ubuntu18_build -f https://raw.githubusercontent.com/stjeong/sample_docker_script/main/dockerfile.ubuntu18.net3 .
docker run -v C:\temp:/app --name test --rm -it net3_ubuntu18_build /bin/bash -c "cd /app/ConsoleApp3 && dotnet build -c Release"

(이로 인해 리눅스용으로 빌드 부산물이 있는 와중에) 뒤이어 윈도우용으로 빌드했더니,

c:\temp\ConsoleApp3> dotnet publish -r win-x64 -c Release /p:SelfContained=true

이런 오류가 발생합니다.

C:\Program Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5)
: error NETSDK1047: Assets file 'c:\temp\ConsoleApp3\obj\project.assets.json' doesn't have a target for 'netcoreapp3.0/win-x64'. Ensure that restore has run and that you have included 'netcoreapp3.0' in the TargetFrameworks for your project. You may also need to include 'win-x64' in your project's RuntimeIdentifiers. [C:\temp\ConsoleApp3\ConsoleApp3.csproj]


메시지에서 언급하는 것처럼, 실제로 "c:\temp\ConsoleApp3\obj\project.assets.json" 파일을 보면 targets 항목에 ".../win-x64"가 없습니다.

{
  "version": 3,
  "targets": {
    ".NETCoreApp,Version=v3.0": {}
  },
 
  ...[생략]...
}

이 문제를 해결하는 간단한 방법은, 빌드 전에 restore를 한 번 해주면 됩니다.

dotnet restore

그다음 다시 빌드하면,

dotnet publish -r win-x64 -c Release /p:SelfContained=true

빌드 과정에서 project.assets.json 파일을 재생성하고 그때는 targets 항목에 ".../win-x64"가 추가됩니다.

{
  "version": 3,
  "targets": {
    ".NETCoreApp,Version=v3.0": {},
    ".NETCoreApp,Version=v3.0/win-x64": {}
  },

  // ...[생략]...
}

재미있는 건, 동일한 상황으로 .NET 5 프로젝트를 대상으로 하면 저 현상이 발생하지 않습니다. 즉, restore를 하지 않아도 dotnet publish 단계에서 project.assets.json 파일을 재생성하고 targets 항목을 추가합니다. 다시 말해, 이 문제는 역사 속으로 그냥 사라질 것입니다. ^^




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







[최초 등록일: ]
[최종 수정일: 7/26/2024]

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

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  [8]  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13707정성태8/6/20245999닷넷: 2292. C# - 자식 프로세스의 출력이 4,096보다 많은 경우 Process.WaitForExit 호출 시 hang 현상파일 다운로드1
13706정성태8/5/20246367개발 환경 구성: 718. Hyper-V - 리눅스 VM에 새로운 디스크 추가
13705정성태8/4/20246523닷넷: 2291. C# 13 - (5) params 인자 타입으로 컬렉션 허용 [2]파일 다운로드1
13704정성태8/2/20246105닷넷: 2290. C# - 간이 dotnet-dump 프로그램 만들기파일 다운로드1
13703정성태8/1/20246171닷넷: 2289. "dotnet-dump ps" 명령어가 닷넷 프로세스를 찾는 방법
13702정성태7/31/20246113닷넷: 2288. Collection 식을 지원하는 사용자 정의 타입을 CollectionBuilder 특성으로 성능 보완파일 다운로드1
13701정성태7/30/20246174닷넷: 2287. C# 13 - (4) Indexer를 이용한 개체 초기화 구문에서 System.Index 연산자 허용파일 다운로드1
13700정성태7/29/20245771디버깅 기술: 200. DLL Export/Import의 Hint 의미
13699정성태7/27/20246241닷넷: 2286. C# 13 - (3) Monitor를 대체할 Lock 타입파일 다운로드1
13698정성태7/27/20246129닷넷: 2285. C# - async 메서드에서의 System.Threading.Lock 잠금 처리파일 다운로드1
13697정성태7/26/20246367닷넷: 2284. C# - async 메서드에서의 lock/Monitor.Enter/Exit 잠금 처리파일 다운로드1
13696정성태7/26/20245952오류 유형: 920. dotnet publish - error NETSDK1047: Assets file '...\obj\project.assets.json' doesn't have a target for '...'
13695정성태7/25/20245649닷넷: 2283. C# - Lock / Wait 상태에서도 STA COM 메서드 호출 처리파일 다운로드1
13694정성태7/25/20246165닷넷: 2282. C# - ASP.NET Core Web App의 Request 용량 상한값 (Kestrel, IIS)
13693정성태7/24/20245662개발 환경 구성: 717. Visual Studio - C# 프로젝트에서 레지스트리에 등록하지 않은 COM 개체 참조 및 사용 방법파일 다운로드1
13692정성태7/24/20246321디버깅 기술: 199. Windbg - 리눅스에서 뜬 닷넷 응용 프로그램 덤프 파일에 포함된 DLL의 Export Directory 탐색
13691정성태7/23/20245919디버깅 기술: 198. Windbg - 스레드의 Win32 Message Queue 정보 조회
13690정성태7/23/20245291오류 유형: 919. Visual C++ 리눅스 프로젝트 - error : ‘u8’ was not declared in this scope
13689정성태7/22/20246217디버깅 기술: 197. Windbg - PE 포맷의 Export Directory 탐색
13688정성태7/21/20245988닷넷: 2281. C# - Lock / Wait 상태에서도 일부 Win32 메시지 처리파일 다운로드1
13687정성태7/19/20245941닷넷: 2280. C# - PostThreadMessage로 보낸 메시지를 Windows Forms에서 수신하는 방법파일 다운로드1
13686정성태7/19/20245861오류 유형: 918. Visual Studio - ATL Simple Object 추가 시 error C2065: 'IDR_...': undeclared identifier
13685정성태7/19/20246115스크립트: 66. Windows 디렉터리 경로를 WSL의 /mnt 포맷으로 구하는 방법 - 두 번째 이야기
13684정성태7/19/20246001닷넷: 2279. C# - 문자열 보간식 사례
13683정성태7/18/20245990오류 유형: 917. ClrMD - Linux 환경의 .NET 5 덤프 분석 시 hang 현상
13682정성태7/18/20245986닷넷: 2278. WPF - 스레드에 종속되는 DependencyObject파일 다운로드1
1  2  3  4  5  6  7  [8]  9  10  11  12  13  14  15  ...