gpt4 book ai didi

c# - 编辑 csproj 文件中的 DefineConstants

转载 作者:行者123 更新时间:2023-12-05 02:23:29 25 4
gpt4 key购买 nike

我有带有以下标签的 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

最佳答案

您可以使用 ReadLinesFromFile , CreatePropertyitem.Replace使用 batching 更新您的属性(property)的功能msbuild 引擎的功能:

  <!-- 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>

关于c# - 编辑 csproj 文件中的 DefineConstants,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22112684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com