2

I'm trying to write a macro/anything else to iterate though all projects and remove all other build configuration other that Active Solution Configuration - Debug and Active Solution Platform - x86. Also after editing the configuration for all projects, I want to set pre-build and post-build events to all projects. I have no clue where to start. Please help. I have like 44 projects in solution and its really hard and time consuming to set all these manually.

Pre Build event:

rd /s /q "$(ProjectDir)bin"

Post Build event:

copy "$(TargetPath)" "$(SolutionDir)TOTALOUTPUT\" /y
Soham Dasgupta
  • 5,061
  • 24
  • 79
  • 125
  • You could look into a continuous integration suite like [CruiseControl](http://www.cruisecontrolnet.org/‎), when you define a project to build you can also define tasks to run before or after like batch files or PowerShell scripts. – Darth Continent Jul 24 '13 at 18:42
  • 1
    Does this have to be a macro or can I present an alternate solution not involving macros to solve your problem? I think this question is amenable to an alternate solution, so if macros aren't required, I can solve this for you; if it is required, you should reword your question to explain why. I don't want this to be a case of IWidget::SetColor (http://blogs.msdn.com/b/oldnewthing/archive/2013/02/06/10391383.aspx). – user314104 Jul 28 '13 at 07:13
  • It has been 9 days since you asked this question, you could have been done with it a long time ago. Send-me-the-code questions don't work very well here, consider a rentacoder kind of site. – Hans Passant Jul 29 '13 at 15:57
  • @user314104 Anything will work. – Soham Dasgupta Jul 31 '13 at 04:44

2 Answers2

6

I could not understand your point clearly but let me try to help...

You can create a new configuration by clickint Build->Configuration Manager->New (top left, there is active solution configuration, click on it you will see New option) Name it and check the projects you wanna compile

Then simply go your solution, select the projects with Ctrl and then leftclick->properties VS allows you to change the properties of multiple projects, so you can easily writes post builds and pre builds events like that, it will work for all projects you selected...

meakgoz
  • 568
  • 4
  • 18
1

You can choose to put this in a macro, or not, however I would actually recommend directly going to the .csproj and .sln files. In the .csproj files they have a series of property groups that specify the build configuration like so:

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <PlatformTarget>x86</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>

If you create a simple script/program/etc that traverses all the .csproj files in question, and read the .csproj xml file. While going through it, you can simply ensure that only the 2 PropertyGroups defining configurations show up. These two configurations will be your debug/release configs. Further, in that same script you can add your pre/post build events, they are simply a different type of property group, such as so:

  <PropertyGroup>
    <PostBuildEvent>xcopy $(TargetName).* "%25SEARCH1%25"\bin\ /i /y</PostBuildEvent>
  </PropertyGroup>

Note: It is likely better to do this as a script when Visual Studio is closed rather than as a macro, but I see no reason why simply wrapping this into a macro wouldn't work either.

Aerophilic
  • 885
  • 2
  • 9
  • 22