20

Is it possible to pass options to linker via comamnd line of msbuild? For example I want to set VC linker option /PROFILE. How to do it without changing of C++ project file?

PS: Visual Studio Express 2012.

ArtDen
  • 253
  • 2
  • 7
  • Possible duplicate of [How to set PreProcessorDefinitions as a task propery for the msbuild task](http://stackoverflow.com/questions/15141429/how-to-set-preprocessordefinitions-as-a-task-propery-for-the-msbuild-task) – stijn Nov 25 '16 at 09:31

1 Answers1

25

Inside the projectfile the linker options are set in an ItemGroup so you cannot simply add or override this from the commandline. Instead you'll have to make msbuild include them which can only be done by importing another msbuild file. This functionality is supported: if you set the ForceImportBeforeCppTargets on the commandline, msbuild will import the file it points to.

Practically: create this file, let's call it c:\props\profile.props

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemDefinitionGroup>
    <Link>
      <Profile>true</Profile>
    </Link>
  </ItemDefinitionGroup>
</Project>

Then build your (unmodified) project like this:

msbuild myProject.vcxproj /p:ForceImportBeforeCppTargets=c:\props\profile.props
stijn
  • 34,664
  • 13
  • 111
  • 163
  • Please see [about](http://stackoverflow.com/about) - if this answered your question, you should mark it as such so it's clear to future visitors that the proposed sultion works – stijn Jul 16 '13 at 14:50
  • I know, but my reputation is less than 15 so I can't mark your answer as useful. Sorry. – ArtDen Jul 17 '13 at 02:25
  • 1
    Wow finally a solution to specify compiler options via msbuild! – Trass3r Nov 25 '16 at 09:26