关于Visual Studio 2010:警告MSB8012:确保$(OutDir),$(TargetName)和$(TargetExt)属性值与%(Link.OutputFile)中指定的值匹配

warning MSB8012 : make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile)

构建代码时出现以下错误。

C:\\Program Files
(x86)\\MSBuild\\Microsoft.Cpp\\v4.0\\Microsoft.CppBuild.targets(990,5):
warning MSB8012:
TargetPath(E:\\Study\\FWIF\\demola\\ext-libs\\libcommoncpp2-1.6.0\\w32\\Debug\\ccgnu2.dll)
does not match the Linker's OutputFile property value
g\\CapeCommon14.dll). This may cause your project to build incorrectly.
To correct this, please make sure that $(OutDir), $(TargetName) and
$(TargetExt) property values match the value specified in
%(Link.OutputFile).

我希望有人会知道该怎么做。


您是否将项目从以前的版本升级到Visual Studio 2010?如果是这样,这是一个众所周知的问题。

Visual Studio 2010 C ++项目升级指南
http://blogs.msdn.com/b/vcblog/archive/2010/03/02/visual-studio-2010-c-project-upgrade-guide.aspx

Warnings during upgrade

Here are some of the common warnings that you may run into during conversion:

1) Linker output directory

One of the warnings you may see when upgrading you applications is MSB8012: $(TargetPath) and Linker’s OutputFile property value does not match:

  • MSB8012: $(TargetExt) ('.dll') does not match the Linker's OutputFile property value 'C:\\foo\\Debug\\MFCActiveX.ocx' ('.ocx') in project configuration 'Debug|Win32'. This may cause your project to build incorrectly. To correct this, please make sure that $(TargetExt) property value matches the value specified in %(Link.OutputFile).

  • MSB8012: $(TargetPath) ('C:\\foo\\Debug\\MFCActiveX.dll') does not match the Linker's OutputFile property value 'C:\\foo\\Debug\\MFCActiveX.ocx' ('C:\\foo\\Debug\\MFCActiveX.ocx') in project configuration 'Debug|Win32'. This may cause your project to build incorrectly. To correct this, please make sure that $(TargetPath) property value matches the value specified in %(Link.OutputFile).
    Link.OutputFile is the value defined at Linker -> General -> Output File on the property page. By default, its value is $(OutDir)$(TargetName)$(TargetExt), which is the same as the value of $(TargetPath). When we convert an application from a previous version, however, there is not an easy way for conversion to parse Link.OutputFile to figure out what exactly the values are for $(TargetName) and $(TargetExt), as different customers may have formatted them in different ways. To work around that, we decided to preserve the value of Linker.OutputFile during conversion. After conversion, $(TargetName) will default to $(ProjectName). $(TargetExt) will default to the default extension for the application type: .dll for Dynamic Library, .lib for Static Library and .exe for Application. Link.OutputFile value will be preserved. Warning MSB8012 will be issued in the conversion log if Link.OutputFile and $(TargetPath) are not the same. You will get the same warnings when building the application.
    $(OutDir), $(TargetName) and $(TargetExt) are exposed on the"General" property page, as"Output Directory","Target Name","Target Extension", respectively. You can manually change the values of these properties so that you no longer get the warning.

  • If your project produces Import Library (Linker -> Advanced -> Import Library), you may need to change the Output folder of the Import Library as well after conversion if the Linker output directory is not the default output directory. Otherwise, the generated import lib maybe in a different directory than the linker output.

  • Debugging.Command is set to default $(TargetPath) after conversion. You may need to make changes so that the right executable will be launched upon F5 (Debugging) or Ctrl + F5 (Start without debugging).


另请参见此处Stackoverflow MSB8012。
将VS2008 C ++项目转换为VS2012时对我有用的方法是:在解决方案资源管理器中右键单击该项目,选择属性,在弹出窗口中:配置属性,链接器,常规。选择右侧的输出文件,这将提供一个下拉菜单,从父级或项目默认值中选择固有的。单击应用。这提供了默认的链接器设置:$(OutDir)$(TargetName)$(TargetExt)。重新生成项目,警告将不再出现。


对于调试DLL,我也遇到了同样的问题,我希望在基名中带有一个尾随的" D"。例如,foo.dll(发布)但fooD.dll(调试)。当您在"调试配置"的链接器设置中优化输出名称时,会出现难看的MSB8012警告。

与Visual Studio 2010一起使用的唯一解决方案似乎是Debug-Configuration的Postbuild-Event:

1
2
3
@echo off
echo Copying $(OutDir)$(TargetName)$(TargetExt) as $(TargetName)D$(TargetExt)
copy /Y $(OutDir)$(TargetName)$(TargetExt) $(OutDir)$(TargetName)D$(TargetExt)


我遇到的情况是我的可执行文件名称与项目名称不同,并且我希望它将可执行文件/ dll构建到与项目所在位置不同的位置。

1)将默认项目名称更改为其他名称。
常规-> TargetName
<我的可执行文件名称>

2)输出到我希望可执行文件生成的其他位置。
常规-> OutputDirectory
<我的新位置在这里>

3)更新链接器设置。
链接器->常规
新值:$(OutDir)$(TargetName)$(TargetExt)
这将采用1和2的新设置。


转到项目->属性->配置属性->链接器->常规部分

将"输出文件"指定为$(OutDir)$(TargetName)$(TargetExt)


从旧项目转换为VS 2010后,我得到了相同的错误。

为了解决这个问题,我创建了一个相同类型的空项目(例如.dll,.lib,.exe)。
然后,将其在"项目属性"中的默认值复制到我的项目中,用于"输出目录","中间目录"和"输出文件"


我通过将项目与工作正常的非常相似的项目进行比较来解决此问题。项目属性中的所有设置都匹配,但是我在发生故障的项目的vcxproj文件中找到以下额外的行:

1
2
3
<Lib>
   <OutputFile>.\\MCtlDrvX.lib</OutputFile>
</Lib>

我删除了它们,消息消失了,输出进入了项目设置中指定的目录。


我设法通过手动编辑vcxproj文件来解决类似的问题。

OutDirTargetName设置位于项目文件的底部。

1
2
3
4
5
6
7
   ...
      <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
        <OutDir>$(OUTPUT_DIRECTORY)\\</OutDir>
        <IntDir>$(ProjectDir)\\$(Configuration)\\$(ProjectName)\\</IntDir>
        <TargetName>$(ProjectName)</TargetName>
      </PropertyGroup>
   </Project>

将块移动到ClCompile块上方可以解决此问题。