locked
Visual Studio 2010 - $(TargetName) macro

    Question

  • We are upgrading visual studio 2005 projects to visual studio 2010 projects.
    There is an option to set $(TargetName) explicitly in project properties, which I have not seen in 2005 version.

    In VS2005 foo.vcproj,
    $(TargetName) = (foo123) same as
    Linker's OutputFile property = (foo123.dll)

    In VS2010 foo.vcxproj,
    $(TargetName) = $(ProjectName) by default = (foo)
    Linker's OutputFile property = (foo123.dll)
    This leads to build warning message and breaks our postbuild script which was expecting $(TargetName) to be same as Linker's OutputFile property

    Is there a way to retain the 2005 behavior?
    Tuesday, February 23, 2010 10:17 PM

Answers

  • Just some background nformation:

    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), $(TargetPath) 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 get the expected value for $(TargetName) or $(TargetPath) and no longer get the warning. Once you make the change, the behavior should be pretty much the same as previous versions of Visual Studio.

    Li Shao, MSFT

     


    Li Shao
    • Marked as answer by Codzilla Wednesday, February 24, 2010 1:19 AM
    Tuesday, February 23, 2010 11:37 PM
  • Unfortunately no ... you would need to manually change the value of $(TargetName) to foo123. This is a design change in VS 2010.
    Renin John Visual C++ Project & Build Team
    • Marked as answer by Codzilla Wednesday, February 24, 2010 1:19 AM
    Tuesday, February 23, 2010 10:36 PM

All replies

  • Unfortunately no ... you would need to manually change the value of $(TargetName) to foo123. This is a design change in VS 2010.
    Renin John Visual C++ Project & Build Team
    • Marked as answer by Codzilla Wednesday, February 24, 2010 1:19 AM
    Tuesday, February 23, 2010 10:36 PM
  • During the development, we couldn't map link.outputfile to TargetName because TargetName has a "global" access while Link.outputfile was just "local" to link.  Losely using global and local here.  We tried to do some workaround but it ended up more complicated with other tools and features such as Lib and property sheets.  We abandoned the workaround all together and required users to set OutDir, TargetName, and TargetExt varibles instead of setting link.outputfile.  In the end, this worked nicely with the other tools and features, as long as the user moved the three named variables.  We also added a build warning before linking to make migration straight forward.

    Thanks

    Felix

    Tuesday, February 23, 2010 11:30 PM
  • Just some background nformation:

    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), $(TargetPath) 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 get the expected value for $(TargetName) or $(TargetPath) and no longer get the warning. Once you make the change, the behavior should be pretty much the same as previous versions of Visual Studio.

    Li Shao, MSFT

     


    Li Shao
    • Marked as answer by Codzilla Wednesday, February 24, 2010 1:19 AM
    Tuesday, February 23, 2010 11:37 PM
  • Thanks for those detail information.
    I got a problem during msbuild process for the same warning number.

    $(TargetPath) is D:\P4\Test\zzzlib\zzzlib\main\obj\RELEASE\bin\CppProjectVC8.exe and looks the linker's output file property value is empty. 

    I've checked this value in MSVS2010 Beta2 from Linker->General->Output File on the property page,it has the same value as $(TargetPath). (D:\P4\Test\zzzlib\zzzlib\main\obj\RELEASE\bin\CppProjectVC8.exe)

    Have no idea why msbuild complain about the Linker's OutputFile property value is empty and not the same as $(TargetPath).

    Thanks!
    =======================================================================
       C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets
     (935,5): warning MSB8012: TargetPath(D:\P4\Test\zzzlib\zzzlib\main\obj\R
     ELEASE\bin\CppProjectVC8.exe) does not match the Linker's OutputFile pro
     perty value (). This may cause your project to build incorrectly. To cor
     rect this, please make sure that $(OutDir), $(TargetName) and $(TargetEx
     t) property values match the value specified in %(Link.OutputFile). [D:\
     P4\Test\zzzlib\zzzlib\main\pkg\ZZZTEST\src\haiyanTest\CppProjectVC8\CppP
     rojectVC8.vcxproj]
    Tuesday, March 02, 2010 2:48 PM
  • This is an interesting case. The default for linker OutputFile is $(OutDir)$(TargetName)$(TargetExt). If Linker OutputFile property is empty, you probably have this in the project file for "Link" tool: <OutputFile></OutputFile>

    Since OutputFile is empty, the exe will be built into the project directory, which is not ideal. The warning is still helpful in that sense. Although in this case, you may want to set OutputFile property instead of changing $(TargetName) or $(OutDir).

    Li Shao, MSFT

     


    Li Shao
    Tuesday, March 02, 2010 6:42 PM
  • Thanks a lot for your reply!

    Actually, the <OutputFile> attribute is correct in the .vcxprj file.

         <OutputFile>D:\P4\Test\zzzlib\zzzlib\main\obj\RELEASE\bin\CppProjectVC8.exe</OutputFile>

    I uninstall the MSVS2010 Beta2, and install MSVS2010 RC1. After that, this error is gone.

    Thanks again!

    Wednesday, March 03, 2010 4:24 AM