我有一个包含1个项目的VS解决方案文件。我一直在尝试编写项目文件,以便有一个构建目标,它将使用不同的编译符号多次构建同一个项目。
此项目是一个旨在用于移动Unity项目的库。该库为每个平台使用#if指令:Android,iOS和Desktop。
我的目标是在具有不同编译符号的不同文件夹中构建相同的项目:
最初,我会手动编辑项目文件,设置编译符号,构建,冲洗和重复。它有点工作,但它很混乱。
然后我发现有一种方法可以在一个项目文件中执行此操作,但我还没弄清楚如何。我试过this没有成功。
为了提供更多的上下文,我使用CakeBuild来构建项目,这就是我调用项目目标的方式:
DotNetBuild("./Lib/Lib.sln", settings => settings.WithTarget("Build"));
我完全可以使用不同的配置或目标多次调用该行,但我还没有找到更改编译符号的方法。
以下是项目文件的片段:
<?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>
当我运行它时,只构建Debug Android。我也尝试在条件(即Condition=" '$(Configuration)|$(Platform)' == 'Debug|iOS' "
)中包含平台,但结果相同。