在未安装Qt VS工具的情况下以Qt/MsBuild格式编译Qt项目 [英] Compiling Qt projects in Qt/MsBuild format without Qt VS Tools installed

查看:2403
本文介绍了在未安装Qt VS工具的情况下以Qt/MsBuild格式编译Qt项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio中使用

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).

我们有一台专门用于夜间构建的计算机,其中仅编译器和msbuild可用(未安装IDE或Qt VS工具).

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:无法找到qt.targets,qt.props;项目可能无法正确构建.

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

之后是几行,例如

e:******** \ Preferences.h(4):致命错误C1083:无法打开包含文件:'ui_Preferences.h':没有此类文件或目录

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

(项目包含Preferences.ui).

未安装Qt VS Tools时如何解决此类错误?

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

推荐答案

工具创建者提供的一种解决方案是将%LOCALAPPDATA%\QtMsBuild复制到每个项目目录中.但是我们正在谈论数百个项目.手动进行操作,以及将其作为项目本身的一部分进行推送,听起来并不优雅.

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.

一个选择是添加一个预构建步骤,将该步骤从一个公共位置复制到每个项目中(并在每个.gitignore文件中添加一个**/QtMsBuild行).同样,看起来工作太多.

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.

查看Qt项目的.vcxproj文件时,您会发现以下片段(创建者提供解决方案的原因):

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>

因此,最简单的解决方案(无法安装工具)是将%LOCALAPPDATA\QtMsBuild目录(从安装了工具的系统中)复制到夜间计算机(在任何常见的地方),但我决定保留工具使用的位置),然后设置环境变量:

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:不要在变量中添加双引号(至少我对它们有问题,因此VS无法找到文件).

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

这篇关于在未安装Qt VS工具的情况下以Qt/MsBuild格式编译Qt项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆