如何在 Xamarin.iOS 项目中使用自定义条件属性排除程序集引用 [英] How to exclude assembly reference using custom conditional properties in Xamarin.iOS project

查看:30
本文介绍了如何在 Xamarin.iOS 项目中使用自定义条件属性排除程序集引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Xamarin.iOS 中有解决方案,其中包含引用非常大的 DLL(绑定非常大的本机库)的项目.所以解决方案的构建时间非常长.在任何源文件中进行简单修改后,我需要等待链接.所以我的想法是使用自定义属性从项目中排除引用,并定义我将在 .cs 文件中使用以排除依赖于大型程序集的代码.但我无法使用自定义条件来排除参考.以下策略不适用于 Xamarin.iOS(但适用于 Visual Studio):

I have solution in Xamarin.iOS with project that references very large DLL (binding for very large native library). So build time for solution is very large. After simple modification in any source file I need to wait for linking. So my idea was to exclude the reference from project using custom property and also to make define that I will use in .cs files to exclude code that depends on large assembly. But I'm unable to use custom condition to exclude the reference. The following strategy will not work for Xamarin.iOS (but will work in Visual Studio):

创建文件 CommonProperties.prop:

Create file CommonProperties.prop:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <LinkWithLargeAssembly>True</LinkWithLargeAssembly>
    </PropertyGroup>
</Project>

所以这个想法是:当它不重要时,我可以将 LinkWithLargeAssembly 定义为 False 并快速链接我的项目.CommonProperties.prop 可以导入到依赖于大型库功能的任何程序集中.

So the idea is: When it is not critical I can define LinkWithLargeAssembly as False and link my project fast. CommonProperties.prop can be imported in any assembly that depends on features of the large library.

在项目文件 .csproj 中导入上面的文件并尝试排除引用(例如 monotouch):

In the project file .csproj import above file and try to exclude reference (for example monotouch):

...
<Import Project="CommonProperties.prop" />
...
<ItemGroup>
    <Reference Include="monotouch" Condition=" '$(LinkWithLargeAssembly)' == 'True' " />
</ItemGroup>
...

我也尝试过直接在项目文件中定义属性 $(LinkWithLargeAssembly) 而无需导入.此外,我尝试使用已定义的属性,例如 $(RootNamespace) 和 $(AssemblyName).但 Condition 属性仅适用于属性 $(Configuration) 和 $(Platform).即以下代码将根据配置包含和排除单点触控:

I've tried also to define property $(LinkWithLargeAssembly) directly in the project file without import. Also I've tried to use already defined properties for example $(RootNamespace) and $(AssemblyName). But Condition attribute works only for properties $(Configuration) and $(Platform). That is following code will include and exclude monotouch depending on the configuration:

<ItemGroup>
    <Reference Include="monotouch" Condition=" '$(Configuration)' == 'Debug' " />
</ItemGroup>

是否可以自定义程序集引用,包括使用我自己的条件属性?

Is it possible to customize assembly reference including using my own conditional properties?

推荐答案

我通过添加从 Debug 复制的新构建配置解决了这个问题.我将其命名为 DebugNoLargeLib.所以我可以使用以下代码排除引用,因为 $(Configuration) 属性将被正确解析:

I solved the problem by adding new build configuration that was copied from Debug. I named it DebugNoLargeLib. So I can exclude reference with the following code because $(Configuration) property will be parsed correctly:

<ItemGroup>
    <Reference Include="SomeLargeLib.dll" Condition=" '$(Configuration)' != 'DebugNoLargeLib' " />
</ItemGroup>

在我将预处理器指令 NO_LARGE_LIB 添加到编译器部分以配置 DebugNoLargeLib 之后.

After I added preprocessor directive NO_LARGE_LIB to the Compiler section for configuration DebugNoLargeLib.

所以现在我可以在没有大型库的情况下进行链接,并从编译中排除依赖于它的代码.

So now I'm able to link without large library and exclude code depending on it from compilation.

但我认为这是 Xamarin 方面的错误,根据 Microsoft 规范不完全支持项目文件处理.

But I think this is mistake from Xamarin side that project files processing is not fully supported according to Microsoft specs.

这篇关于如何在 Xamarin.iOS 项目中使用自定义条件属性排除程序集引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆