gpt4 book ai didi

c++ - 使用 MsBuild 构建 Visual Studio Code

转载 作者:太空狗 更新时间:2023-10-29 22:56:36 25 4
gpt4 key购买 nike

我正在尝试使用 visual studio code 构建一个 C++ 项目。

我为自动构建创建了一个 task.json。

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "msbuild",
"args": [
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true",
"/t:build"
],
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "silent"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
}
]
}

它抛出以下异常。

MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
The terminal process terminated with exit code: 1

由于构建任务基于 MSBuild。 MSBuild 需要 .vcxproj 文件进行构建。

是否有任何命令可以通过nuget 或msbuild 生成.vcxproj。

最佳答案

我不知道有什么工具可以为您生成一个工具,但这篇 MSDN 文章将为您提供所需的信息:

https://msdn.microsoft.com/en-us/library/dd293607.aspx

工作项目的完整示例是:

<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  
<ItemGroup>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.default.props" />
<PropertyGroup>
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</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>

在 ClCompile Include 属性中,您可以使用通配符,这样您就不必不断更新项目文件。

有关 MSBuild 项的更多信息,请参阅这篇 MSDN 文章:

https://msdn.microsoft.com/en-us/library/ms171453.aspx

关于c++ - 使用 MsBuild 构建 Visual Studio Code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47374002/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com