0

I have a VS solution file that contains 1 project. I've been trying to write the project file such that there's a single build target that will build the same project multiple times with different compilation symbols each.

This project is a library that is intended to be used in a mobile Unity project. The library uses #if directives for each platform: Android, iOS and Desktop.

My goal is to build the same project in a different folder with different compilation symbols:

  • Debug
    • Android
      • Lib.DLL ("UNITY_ANDROID" compilation symbols)
    • iOS
      • Lib.DLL ("UNITY_IPHONE" compilation symbols)
    • Standalone
      • Lib.DLL ("" compilation symbols)
  • Release
    • Android
      • Lib.DLL ("UNITY_ANDROID" compilation symbols)
    • iOS
      • Lib.DLL ("UNITY_IPHONE" compilation symbols)
    • Standalone
      • Lib.DLL ("" compilation symbols)

Originally, I would manually edit the project file, set the compilation symbols, build, rinse and repeat. It kinda worked, but it was messy.

I then discovered that there's a way to do this in a single project file, but I have yet to figure out how. I've tried this with no success.

To give a little more context, I'm using CakeBuild to build the project and this is how I'm calling the project target:

DotNetBuild("./Lib/Lib.sln", settings => settings.WithTarget("Build"));

I am totally OK with calling that line multiple times with different configurations or targets, but I have not found a way to change the compilation symbols.

Here's a snippet of the project file:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{CF15E877-F285-496B-B748-C9A666D97D0F}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>JsonDotNet</RootNamespace>
    <AssemblyName>JsonDotNet</AssemblyName>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <TargetFrameworkProfile />
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Debug-Android' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\Android\lib\net35\</OutputPath>
    <DefineConstants>UNITY_ANDROID</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Debug-iOS' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\iOS\lib\net35\</OutputPath>
    <DefineConstants>UNITY_IPHONE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Debug-x86' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\iOS\lib\net35\</OutputPath>
    <DefineConstants></DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Release-Android' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\Android\lib\net35\</OutputPath>
    <DefineConstants>UNITY_ANDROID</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Release-iOS' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\iOS\lib\net35\</OutputPath>
    <DefineConstants>UNITY_IPHONE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Release-x86' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\iOS\lib\net35\</OutputPath>
    <DefineConstants></DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
    <ItemGroup>
        <ProjectToBuild Include="..\Lib.sln">
            <Properties>Configuration=Debug-iOS</Properties>
        </ProjectToBuild>
        <ProjectToBuild Include="..\Lib.sln">
            <Properties>Configuration=Debug-Android</Properties>
        </ProjectToBuild>
        <ProjectToBuild Include="..\Lib.sln">
            <Properties>Configuration=Debug-x86</Properties>
        </ProjectToBuild>
        <ProjectToBuild Include="..\Lib.sln">
            <Properties>Configuration=Release-iOS</Properties>
        </ProjectToBuild>
        <ProjectToBuild Include="..\Lib.sln">
            <Properties>Configuration=Release-Android</Properties>
        </ProjectToBuild>
        <ProjectToBuild Include="..\Lib.sln">
            <Properties>Configuration=Release-x86</Properties>
        </ProjectToBuild>
    </ItemGroup>
    <Target Name="Build">
        <MSBuild Projects="@(ProjectToBuild)" BuildInParallel="true" />
    </Target>

When I run this, only Debug Android is built. I've also tried including the platform in the condition (i.e. Condition=" '$(Configuration)|$(Platform)' == 'Debug|iOS' ") with the same results.

Community
  • 1
  • 1
pek
  • 17,847
  • 28
  • 86
  • 99
  • No experience with cakebuild, but if you'd just run 'msbuild lib.sln /p:Configuration=Debug-Android' it sould build that configuration, and hence use the UNITY_ANDROID etc? – stijn May 14 '16 at 12:14
  • @stijn Thanks for your comment. I just tried that and this is what I'm getting: "error MSB4126: The specified solution configuration "Debug-Android|AnyCPU" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration." – pek May 14 '16 at 14:46

0 Answers0