Question

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):

Create file 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. CommonProperties.prop can be imported in any assembly that depends on features of the large library.

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

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?

Was it helpful?

Solution

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>

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top