When running a built project in Visual Studio 2019, an error appears MSB3073


|Ошибка|MSB3073|выход из команды setlocal
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy Bypass -file D:/forked_projects/VCMI/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary D:/forked_projects/VCMI/build/bin/Debug/VCMI_client.exe -installedDir D:/forked_projects/VCMI/vcpkg/installed/x64-windows/debug/bin -OutVariable out
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
setlocal
cd D:\forked_projects\VCMI\build\bin\Debug
if %errorlevel% neq 0 goto :cmEnd
D:
if %errorlevel% neq 0 goto :cmEnd
C:\Program Files\CMake\bin\cmake.exe -E copy AI/fuzzylite.dll fuzzylite.dll
if %errorlevel% neq 0 goto :cmEnd
C:\Program Files\CMake\bin\cmake.exe -E copy AI/tbb.dll tbb.dll
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
:VCEnd с кодом 1.|VCMI_client|D:\Program Files\Microsoft Visual Studio 2019\Community\Msbuild\Microsoft\VC\v160\Microsoft.CppCommon.targets|155||

How to fix this error?

Does it work if you run vcmi_client.exe directly?

Might be that copying dlls does not work for whatever reason.

C:\Program Files\CMake\bin\cmake.exe -E copy AI/fuzzylite.dll fuzzylite.dll

What cmake version do you have?

I am using cmake version 3.25.1.
When I run vcmi_client.exe in the debug directory I get the following errors:
Not found SDL2_mixer.dll and SDL2.dll
All other .exes crash with ‘abort() has been called’ error.

There is no MSB3073 error in the release build.
.exe run, but immediately crash with an error.

Error when launching release vcmi_client.exe.
All other release exe crashes with the same error.

I think I found a mistake.
There is such a text in the build logs (INSTALL. log) .
Cmake Error at cmake_install.cmake:37 (file) :
file cannot create directory :C:/Program Files/VCMI… Maybe need administrative privileges.

but which directory is it trying to create there? The install location is essentially read-only for VCMI. The “editable” place is under user directory.

oh, or are you building inside Program Files? That’s definitely a bad choice :slight_smile:

Solution problem:
1)Open vcmiclient.vcxproj with text editor
2)Find line:

Blockquote
<Target Name=“PostBuildEvent” Condition="’$(PostBuildEventUseInBuild)’!=‘false’"!>
<Message Text="%(PostBuildEvent.Message)" Condition="’%(PostBuildEvent.Message)’ != ‘’ and ‘%(PostBuildEvent.Command)’ != ‘’" Importance=“High” /!>
<Exec Command="%(PostBuildEvent.Command)$(_BuildSuffix)" StdOutEncoding="%(PostBuildEvent.StdOutEncoding)" StdErrEncoding="%(PostBuildEvent.StdErrEncoding)" Condition="’%(PostBuildEvent.Command)’ != ‘’"/!>
</Target!>

3)Delete her and save vcmiclient.vcxproj
4)Rebuild VCMI_client

Breaks MSBuild. It should not be deleted, but commented on.

editing the generated vcxproj is a workaround at best and most probably can be done by adjusting CMakeLists.txt, I suggest to find the source of the issue.

cannot create directory :C:/Program Files/VCMI

it’s still unclear what is trying to reference VCMI in PF and why.

tbh currently looks like a local environment issue.

1)Note open:
D:\Program Files\Microsoft Visual Studio 2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets
2)Comment out the line
I made a mistake.

I still don’t understand what’s wrong on your side… Did you break something in Visual Studio itself?

you could also explain your issue in Russian, hopefully it’d be come clear then.

Хорошо, я напишу по-русски все проблемы. :slightly_smiling_face: У меня стоят две версии Microsoft Visual studio 2019 и Microsoft Visual studio 2022.
Через CMake по инструкции я собираю готовый проект, указываю генератор Visual Studio 19. Все собирается отлично без ошибок. Проблемы начинаются, когда я пытаюсь стартануть проект под Visual studio в режиме Debug. Проект собирается нормально, но не стартует - выдает ошибку ‘MSB3073’. Она видна на скриншоте выше. В режиме Release таких проблем нету, проект запускается без всяких ошибок.
Я нашел обходной путь для решения этой проблемы, закомментировал строчку Microsoft.CppCommon.targets в MSBuildMicrosoft, все стартует под Debug корректно но она ЛОМАЕТ систему сборки. То есть, собрать что-то CMake уже не получиться - выдаст ошибку. Этот не самый лучший вариант.
Еще одна проблема возникает, когда я запускаю готовый собранный debug-проект (не из под IDE). При запуске любого сценария, выпадает ошибка “Cannot open dynamic library (.\AI\VCAI.dll). Throwing…”
То есть, судя по всему отладчик не видит DLL. Повторюсь в релизной сборке таких проблем нету, только в дебаге.
Я почитал форумы, пишут что нужно указать переменную PATH к dll-кам в настройках отладчика, но у меня пока это не получается.
Можно конечно плюнуть на debug сборку и собирать все под release, но что-то мне подсказывает это не совсем правильно.
Вроде пока все.

а принципиально иметь две студии установленных? можно ж поставить лишь 22 и просто добавить toolset от 19-й. Может это устранит проблему.

а если запускать дебаг просто так, а не из студии, проблемы нет? в таком случае можно просто прицепиться отладчиком вручную.

и все же я до сих пор не понимаю с чего вдруг что-то пытается создать папку C:/Program Files/VCMI…

@Nullkiller есть идеи?

Просто когда я читал гайд по сборке я особо не задумывался, что в 22 можно добавить toolset от 19-й. Да и не знал я, что так можно сделать, по этому пришлось еще ставить 19 студию. Для меня это было бы проще и быстрее по времени, чем разбираться в настройках.
Попробую запустить дебаг просто так, посмотрю что получиться.
" и все же я до сих пор не понимаю с чего вдруг что-то пытается создать папку C:/Program Files/VCMI… ". Возможно это я что-то химичил с путями, пока пытался решить проблему. По этому лучше не заострять на этом внимание, данную ошибку я больше не видел.

C:/Program Files/VCMI - probably you debug INSTALL and it tries to install VCMI and by default it does install to C:/Program Files/VCMI. You could try to open the solution using File/Open/Cmake… and open root CMakeList.txt. It will generate solution itself. Settings it wil ltake from CMakePresets.json. Not official way from our side but this is how Microsoft wants and should be less problematic. INSTALL is better debuggable because it will put all required dlls to the output dir while regular build may skip some

У меня возникла еще пара проблем:
1)Как изменить генератор на visual studio 19? Прикрепил скриншот:

2)При установке visual studio toolset 19 в visual studio 22 при сборке через cmd он ее в упор не видит. Пишет “could not find any instance of Visual Studio 19”. Что я делаю не так?

тулсеты выбираются через опцию CMAKE_GENERATOR_TOOLSET, например:

-D CMAKE_GENERATOR_TOOLSET="v141,version=14.16"

она точно передается?

Нет. Я думал это все на автомате подхватывается. Сейчас попробую.

Не могу сказать как оно там работает, всегда собирал с msvc через командную строку.
Тут наверное лучше всего почитать документацию к cmake интеграции в VS.