如果我不想使用Visual Studio IDE的功能,是否可以安装非时限/non-non-30--Microsoft C 编译器(哪个版本?(和直接从命令行?
直接构建.sln或.vcxproj project这是我成功用于单个.cpp文件项目的方法:
call "C:Program Files (x86)Microsoft Visual Studio 12.0VCvcvarsall.bat" x86
cl helloworld.cpp /link user32.lib
有没有办法将其扩展到.sln或.vcxproj项目?
我对此使用devenv
。请注意,至少在VS 2017社区中,您必须打开VS GUI并使用Microsoft帐户登录,否则它将在30天后停止允许编译。
PATH=%PATH%;C:Program Files (x86)Microsoft Visual Studio2017CommunityCommon7IDE
devenv Solution.sln /build Debug /project project
(即使您不运行vcvarsall.bat
,这也有效,这很好(
如果我们要不是使用IDE,则可以仅安装VS构建工具(安装程序为VS2019命名为vs_BuildTools.exe
(,然后只使用msbuild
。
示例:https://learn.microsoft.com/en-us/cpp/cpp/build/walkthrough-using-msbuild-to-to-create-create-a-visual-cpp-project?view = mmsvc-160
build.bat:
MSBuild.exe helloworld.vcxproj /p:configuration=release /p:platform=x64
helloworld.vcxproj:
<Project DefaultTargets="Build" ToolsVersion="16.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<Import Project="$(VCTargetsPath)Microsoft.Cpp.default.props" />
<PropertyGroup>
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)Microsoft.Cpp.props" />
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)Microsoft.Cpp.Targets" />
</Project>
main.cpp:
#include <iostream>
#include "main.h"
int main()
{
std::cout << "Hello, from MSBuild!n";
return 0;
}
和一个空的main.h文件。
在这种情况下确实需要.sln文件。