msbuild Link 步骤没有 运行

msbuild Link step doesn't run

我正在尝试使用 MSBuild 构建一个非常简单的 C 程序。以前这是由一名实习生使用 Visual Studio 组合在一起的,但我们不会在这里使用 VS,我希望它是用 MSBuild 构建的,这样我就可以自动化它。

我按照 MSDN 上的演练和那里的其他参考文档从头开始构建了我的 vcxproj 文件。我能够毫无问题地编译 obj 文件,但是 Link 步骤似乎从来没有 运行 所以我没有得到可执行输出。

在 AppDrv.c 文件中有一个名为 main 的函数,可以安全地假设它将被 linker 检测为入口点,还是我需要手动告诉 msbuild 一些这是怎么回事?

这是我的 vcxproj 的全部内容。我在文档中找不到任何说我需要告诉它 link 的内容,如果 CL 步骤完成,它不应该自动发生吗?我是否需要以某种方式明确地将 obj 文件列出到 link,或者 MSBuild 可以自己解决这个问题?

<Project DefaultTargets="Build" ToolsVersion="14.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>Console</ConfigurationType>
    <PlatformToolset>v140</PlatformToolset>
  </PropertyGroup>


  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <!--Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /-->


  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>false</LinkIncremental>
    <IncludePath>$(UniversalCRT_IncludePath)$(ProjectDir)helper\include;$(WindowsSDK_IncludePath)$(VC_IncludePath)</IncludePath>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <CompileAs>CompileAsC</CompileAs>
      <WarningLevel>TurnOffAllWarnings</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <OutputFile>slip_windows_helper.exe</OutputFile>
      <ShowProgress>LinkVerbose</ShowProgress>
    </Link>
  </ItemDefinitionGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
    <IncludePath>$(UniversalCRT_IncludePath)$(ProjectDir)helper\include;$(WindowsSDK_IncludePath)$(VC_IncludePath)</IncludePath>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <CompileAs>CompileAsC</CompileAs>
      <WarningLevel>TurnOffAllWarnings</WarningLevel>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
  </ItemDefinitionGroup>


  <ItemGroup>
    <ClCompile Include="$(ProjectDir)helper\src\AppDrv.c" />
    <ClCompile Include="$(ProjectDir)helper\src\Buffers.c" />
    <ClCompile Include="$(ProjectDir)helper\src\SingleThreadAsync.c" />
    <ClCompile Include="$(ProjectDir)helper\src\Slip.c" />
    <ClCompile Include="$(ProjectDir)helper\src\Utils.c" />
  </ItemGroup>

  <ItemGroup>
    <ClInclude Include="$(ProjectDir)helper\include\AppDrv.h" />
    <ClInclude Include="$(ProjectDir)helper\include\Buffers.h" />
    <ClInclude Include="$(ProjectDir)helper\include\SingleThreadAsync.h" />
    <ClInclude Include="$(ProjectDir)helper\include\Slip.h" />
    <ClInclude Include="$(ProjectDir)helper\include\Utils.h" />
    <ClInclude Include="$(ProjectDir)helper\include\SharedHeader.h" />
  </ItemGroup>


  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Targets" />


    <Target Name="Info">
        <Message Text="Target to output MSBuild information" />
        <Message Text="OutputAssembly: $(OutputAssembly)" />
        <Message Text="VCTargetsPath: $(VCTargetsPath)" />
        <Message Text="Includes: $(IncludePath)" />
        <Message Text="VC_IncludePath:$(VC_IncludePath)" />
        <Message Text="WindowsSDK_IncludePath:$(WindowsSDK_IncludePath)" />
        <Message Text="the property config is: $(Configuration)" />
        <Message Text="final output directory: $(OutDir)" />
    </Target>


</Project>

这是我用来启动构建的命令:

MSBuild.exe slipwinhelper.vcxproj /p:configuration=Debug /p:platform=Win32 /p:OutDir=target\ /nologo /t:Clean;Build;Info

更新: 我通过覆盖 AfterBuild 事件得到了 运行 link 任务:

  <Target Name="AfterBuild">
      <Link Sources="Debug\AppDrv.obj;Debug\Buffers.obj;Debug\SingleThreadAsync.obj;Debug\Slip.obj;Debug\Utils.obj" />
  </Target>

但现在它在代码中的 SetupApi 调用上给我未解决的外部问题。我已经尝试将子系统更改为 Windows,但似乎不起作用。

与 VS 生成的文件的快速比较显示了一堆 differences/lacking 属性,包括来自 VS 的文件具有

<ConfigurationType>Application</ConfigurationType>

而您指定的 Console msbuild 无法识别。