Compiling Qt projects in Qt/MsBuild format without Qt VS Tools installed

眉间皱痕 提交于 2019-12-10 18:40:08

问题


I have many Qt projects in Visual Studio, using the new Qt/MsBuild format provided by the Qt VS Tools. When compiling in my development environment, where I have the Qt VS Tools installed, everything works flawlessly (compiling from IDE and from command line).

We have a computer dedicated to nightly builds, where only the compiler and msbuild are available (no IDE nor Qt VS Tools are installed).

When compiling the projects in such computer we get an error:

QtMsBuild: could not locate qt.targets, qt.props; project may not build correctly.

Followed by several lines such as

e:********\Preferences.h(4): fatal error C1083: Cannot open include file: 'ui_Preferences.h': No such file or directory

(Project contains Preferences.ui).

How can I solve such errors when Qt VS Tools are not installed?


回答1:


One solution provided by the Tools' creators is to copy %LOCALAPPDATA%\QtMsBuild into each project directory. But we are talking about hundred of projects. Doing manually, and more on, pushing them as part of the project itself doesn't sound very elegant.

One option would be to add a pre-build step that copies it from a common place into each project (and adding a **/QtMsBuild line to each .gitignore file). Again, looks like too much work.

When looking at the .vcxproj file for the Qt project you find this fragment (the reason for the solution provided by creators):

<PropertyGroup Condition="'$(QtMsBuild)'=='' or !Exists('$(QtMsBuild)\qt.targets')">
  <QtMsBuild>$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
</PropertyGroup>

So, the simplest solution (without being able to install the tools), is to copy the %LOCALAPPDATA\QtMsBuild directory (from a system with the Tools installed) into the night computer (in any common place, but I decided to keep the location used by the tools) and then setting an environment variable:

set QtMsBuild=%LOCALAPPDATA%\QtMsBuild

PS: do not add double quotes to the variable (at least I had problems with them, so VS couldn't find the files).



来源:https://stackoverflow.com/questions/51082148/compiling-qt-projects-in-qt-msbuild-format-without-qt-vs-tools-installed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!