简体   繁体   English

如何在Xamarin.iOS项目中使用自定义条件属性排除程序集引用

[英]How to exclude assembly reference using custom conditional properties in Xamarin.iOS project

I have solution in Xamarin.iOS with project that references very large DLL (binding for very large native library). 我在Xamarin.iOS中有解决方案,该项目引用了非常大的DLL(非常大的本机库的绑定)。 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. 所以我的想法是使用自定义属性从项目中排除引用,并且还要定义我将在.cs文件中使用以排除依赖于大型程序集的代码。 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): 以下策略不适用于Xamarin.iOS(但可以在Visual Studio中使用):

Create file CommonProperties.prop: 创建文件CommonProperties.prop:

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

So the idea is: When it is not critical I can define LinkWithLargeAssembly as False and link my project fast. 所以我的想法是:当它不重要时,我可以将LinkWithLargeAssembly定义为False并快速链接我的项目。 CommonProperties.prop can be imported in any assembly that depends on features of the large library. CommonProperties.prop可以导入任何依赖于大型库的功能的程序集中。

In the project file .csproj import above file and try to exclude reference (for example monotouch): 在项目文件.csproj导入上面的文件并尝试排除引用(例如monotouch):

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

I've tried also to define property $(LinkWithLargeAssembly) directly in the project file without import. 我也尝试过直接在项目文件中定义属性$(LinkWithLargeAssembly)而不导入。 Also I've tried to use already defined properties for example $(RootNamespace) and $(AssemblyName). 此外,我尝试使用已定义的属性,例如$(RootNamespace)和$(AssemblyName)。 But Condition attribute works only for properties $(Configuration) and $(Platform). 但Condition属性仅适用于属性$(Configuration)和$(Platform)。 That is following code will include and exclude monotouch depending on the configuration: 这是以下代码将包括和排除monotouch取决于配置:

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

Is it possible to customize assembly reference including using my own conditional properties? 是否可以自定义程序集引用,包括使用我自己的条件属性?

I solved the problem by adding new build configuration that was copied from Debug. 我通过添加从Debug复制的新构建配置解决了这个问题。 I named it DebugNoLargeLib. 我把它命名为DebugNoLargeLib。 So I can exclude reference with the following code because $(Configuration) property will be parsed correctly: 所以我可以用以下代码排除引用,因为$(Configuration)属性将被正确解析:

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

After I added preprocessor directive NO_LARGE_LIB to the Compiler section for configuration DebugNoLargeLib. 我将预处理程序指令NO_LARGE_LIB添加到编译器部分以获取配置DebugNoLargeLib。

So now I'm able to link without large library and exclude code depending on it from compilation. 所以现在我能够在没有大型库的情况下进行链接,并根据编译来排除代码。

But I think this is mistake from Xamarin side that project files processing is not fully supported according to Microsoft specs. 但我认为这是Xamarin方面的错误,根据Microsoft规范,项目文件处理并不完全支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM