我的csproj包含以下标记:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Bin\Debug</OutputPath>
<DefineConstants>TRACE;DEBUG;SILVERLIGHT;WINDOWS_PHONE;SUPPORTS_ICLOUD</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
如果你看到我添加了一个名为SUPPORTS_ICLOUD
的宏。
我有.txt文件,我有以下内容:
#define SUPPORTS_IN_APP_PURCHASE
#define BUTTON_THEME
#define SUPPORTS_TITLE
#define HAS_HTML_IMAGE_CONTENT
#define TINT_COLOR
#define NAVIGATIONTITLE_TEXT_COLOR
#define SUPPORTS_ICLOUD
正如你在我的文本文件中看到的那样,我定义了很多宏,现在我可以将它作为一个文件或一个字符串完全传递,而不是传递DefineConstants
中的每个宏,这样它就会占用所有这些宏?这可能还是有其他办法吗?
修改
这是我的csproj文件:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{0D446418-B7CD-4624-91F4-F3E382F8DD23}</ProjectGuid>
<ProjectTypeGuids>{C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>POCChild3</RootNamespace>
<AssemblyName>POCChild3</AssemblyName>
<TargetFrameworkIdentifier>WindowsPhone</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v8.0</TargetFrameworkVersion>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
<SilverlightApplication>true</SilverlightApplication>
<SupportedCultures>
</SupportedCultures>
<XapOutputs>true</XapOutputs>
<GenerateSilverlightManifest>true</GenerateSilverlightManifest>
<XapFilename>POCChild3_$(Configuration)_$(Platform).xap</XapFilename>
<SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate>
<SilverlightAppEntry>POCChild3.App</SilverlightAppEntry>
<ValidateXaml>true</ValidateXaml>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Bin\Release\</OutputPath>
<DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>Bin\Release</OutputPath>
<DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<MacroFile>Macros.txt</MacroFile>
</PropertyGroup>
<Target Name="Build">
<ReadLinesFromFile
File="$(MacroFile)" >
<Output
TaskParameter="Lines"
ItemName="MacrosFromFile"/>
</ReadLinesFromFile>
<CreateProperty
Value="@(MacrosFromFile->Replace('#define ', ''))">
<Output
TaskParameter="Value"
PropertyName="FileDefineConstants" />
</CreateProperty>
<CreateProperty
Value="$(DefineConstants);$(FileDefineConstants)">
<Output
TaskParameter="Value"
PropertyName="DefineConstants" />
</CreateProperty>
<Message Text="Const >> $(DefineConstants)" />
</Target>
在我的MainPage.cs文件中;
#if SUPPORTS_ICLOUD
AppName.Text = "ABCD";
Debug.WriteLine("App type is app with main screen");
#endif
答案 0 :(得分:2)
您可以使用ReadLinesFromFile,CreateProperty和item.Replace函数通过使用msbuild引擎的batching功能来更新您的媒体资源:
<!-- property defintion -->
<PropertyGroup>
<MacroFile>def.txt</MacroFile> <!-- the filename with your #defines -->
</PropertyGroup>
<!-- other stuff in your build file -->
<!-- import common targets near the end of your build file -->
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- override targets (make sure this is AFTER the import elements) -->
<!-- BeforeBuild is pre-dfined target which can be overriden -->
<Target Name="BeforeBuild">
<!-- Open the #define file and read every line in items named
MacrosFromFile
-->
<ReadLinesFromFile
File="$(MacroFile)" >
<Output
TaskParameter="Lines"
ItemName="MacrosFromFile"/>
</ReadLinesFromFile>
<!-- Create a new property called FileDefineConstants combining
every Item from MacrosFromFile
using the built-in replace statement to get
rid of the #define instruction
-->
<CreateProperty
Value="@(MacrosFromFile->Replace('#define ', ''))">
<Output
TaskParameter="Value"
PropertyName="FileDefineConstants" />
</CreateProperty>
<!-- re-create the orignal DefineConstants combining the current value
and the value from FileDefineConstants -->
<CreateProperty
Value="$(DefineConstants);$(FileDefineConstants)">
<Output
TaskParameter="Value"
PropertyName="DefineConstants" />
</CreateProperty>
<Message Text="Const >> $(DefineConstants)" />
</Target>