Skip to content

[msbuild] Enable design-time builds for binding projects when bundling original resources. Fixes #10148. #22985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions msbuild/Xamarin.Shared/Xamarin.Shared.ObjCBinding.targets
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Copyright (C) 2020 Microsoft. All rights reserved.

<Target Name="_CollectGeneratedSources"
DependsOnTargets="_GenerateBindings;_CompressNativeFrameworkResources"
Condition="'$(DesignTimeBuild)' != 'true'"
Condition="'$(_DisableBindingProjectBuild)' != 'true'"
>

<ReadLinesFromFile File="$(_GeneratedSourcesFileList)" >
Expand Down Expand Up @@ -109,7 +109,7 @@ Copyright (C) 2020 Microsoft. All rights reserved.
</ItemGroup>
</Target>

<Target Name="_PrepareNativeReferences" Condition="'$(DesignTimeBuild)' != 'true'" DependsOnTargets="_SanitizeNativeReferences">
<Target Name="_PrepareNativeReferences" Condition="'$(_DisableBindingProjectBuild)' != 'true'" DependsOnTargets="_SanitizeNativeReferences">
<PrepareNativeReferences
IntermediateOutputPath="$(IntermediateOutputPath)"
NativeReferences="@(NativeReference)"
Expand Down
3 changes: 3 additions & 0 deletions msbuild/Xamarin.Shared/Xamarin.Shared.props
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ Copyright (C) 2020 Microsoft. All rights reserved.

<!-- Default NoBindingEmbedding to 'true' for .NET projects, it's the new way -->
<NoBindingEmbedding Condition="'$(NoBindingEmbedding)' == ''">true</NoBindingEmbedding>

<!-- We don't want to build a binding project when in design time mode, and not bundling original resources, because we might end up requiring a connection to a remote mac, which is not a good idea for a supposedly quick design-time build. -->
<_DisableBindingProjectBuild Condition="'$(_DisableBindingProjectBuild)' == '' And '$(BundleOriginalResources)' != 'true' And '$(DesignTimeBuild)' == 'true'">true</_DisableBindingProjectBuild>
</PropertyGroup>

<Target Name="_ComputeTargetFrameworkMoniker" Condition="'$(_ComputedTargetFrameworkMoniker)' == ''">
Expand Down
8 changes: 4 additions & 4 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
@(NativeReference) are not safe to use as an Input to a task, as frameworks are a directory and will appears unbuilt every time.
So we split it into two camps as a prebuild step
-->
<Target Name="_ExpandNativeReferences" Condition="'$(DesignTimeBuild)' != 'true'" DependsOnTargets="_DetectSdkLocations;_ComputeTargetArchitectures;_GenerateBundleName;_SanitizeNativeReferences">
<Target Name="_ExpandNativeReferences" Condition="'$(_DisableBindingProjectBuild)' != 'true'" DependsOnTargets="_DetectSdkLocations;_ComputeTargetArchitectures;_GenerateBundleName;_SanitizeNativeReferences">
<ItemGroup>
<_XCFrameworkNativeReference Include="@(NativeReference -> '%(Identity)/.')" Condition="'%(Extension)' == '.xcframework' Or $([MSBuild]::ValueOrDefault('%(FileName)%(Extension)', '').EndsWith('.xcframework.zip'))" />
<_FrameworkNativeReference Include="@(NativeReference -> '%(Identity)/%(Filename)')" Condition="'%(Extension)' == '.framework'" />
Expand Down Expand Up @@ -174,7 +174,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
</PropertyGroup>

<Target Name="_CreateBindingResourcePackage"
Condition="'$(DesignTimeBuild)' != 'true' And '$(NoBindingEmbedding)' == 'true'"
Condition="'$(_DisableBindingProjectBuild)' != 'true' And '$(NoBindingEmbedding)' == 'true'"
DependsOnTargets="_ExpandNativeReferences"
Inputs="$(MSBuildAllProjects);$(MSBuildProjectFullPath);@(ObjcBindingApiDefinition);@(ObjcBindingCoreSource);@(ReferencePath);@(ObjcBindingNativeLibrary);@(_FrameworkNativeReference);@(_FileNativeReference)"
Outputs="$(BindingResourcePath).stamp">
Expand Down Expand Up @@ -1859,7 +1859,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
@(_CompiledApiDefinitionsCompile);"
Outputs="$(_CompiledApiDefinitionAssembly);$(_CompiledApiDefinitionDocumentationFile)"
DependsOnTargets="_ComputeCompileApiDefinitionsInputs"
Condition="'$(IsBindingProject)' == 'true' And '$(DesignTimeBuild)' != 'true'"
Condition="'$(IsBindingProject)' == 'true' And '$(_DisableBindingProjectBuild)' != 'true'"
>

<!-- This is a mirror of the method GetCompiledApiBindingsAssembly in BindingTouch.cs where the compilation is done inside bgen -->
Expand Down Expand Up @@ -1897,7 +1897,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
Inputs="$(MSBuildAllProjects);@(ObjcBindingApiDefinition);@(ObjcBindingCoreSource);@(ReferencePath);@(ObjcBindingNativeLibrary)"
Outputs="$(_GeneratedSourcesFileList)"
DependsOnTargets="$(_GenerateBindingsDependsOn)"
Condition="'$(IsBindingProject)' == 'true' And '$(DesignTimeBuild)' != 'true'">
Condition="'$(IsBindingProject)' == 'true' And '$(_DisableBindingProjectBuild)' != 'true'">

<Error Condition="'$(IsMacEnabled)' != 'true' And '$(BuildBindingProjectLocally)' != 'true'" Text="The property 'BuildBindingProjectLocally' build is disabled, but there's no connection to a remote Mac." />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!--
***********************************************************************************************
Xamarin.iOS.ObjcBinding.CSharp.After.targets
Expand All @@ -19,29 +19,6 @@ Copyright (C) 2013-2016 Xamarin Inc. All rights reserved.
<Import Project="$(MSBuildThisFileDirectory)Xamarin.iOS.Windows.After.targets" Condition="Exists('$(MSBuildThisFileDirectory)Xamarin.iOS.Windows.After.targets')" />

<UsingTask TaskName="Xamarin.MacDev.Tasks.PrepareObjCBindingNativeFrameworks" AssemblyFile="$(CoreiOSSdkDirectory)$(_TaskAssemblyFileName)" />

<PropertyGroup Condition="'$(DesignTimeBuild)' != 'true'">
<CompileDependsOn>
_SetupDesignTimeBuildForCompile;
$(CompileDependsOn)
</CompileDependsOn>
<BuildDependsOn>
_SetupDesignTimeBuildForBuild;
$(BuildDependsOn);
</BuildDependsOn>
</PropertyGroup>

<Target Name="_SetupDesignTimeBuildForCompile">
<PropertyGroup>
<DesignTimeBuild Condition=" '$(DesignTimeBuild)' == '' ">true</DesignTimeBuild>
</PropertyGroup>
</Target>

<Target Name="_SetupDesignTimeBuildForBuild">
<PropertyGroup>
<DesignTimeBuild Condition=" '$(DesignTimeBuild)' == '' ">false</DesignTimeBuild>
</PropertyGroup>
</Target>

<Target Name="CopyCompressedNativeFrameworkResources" Condition="'@(_NativeFrameworkResource)' != ''" AfterTargets="_CompressNativeFrameworkResources">
<CopyFileFromBuildServer SessionId="$(BuildSessionId)" File="$(IntermediateOutputPath)%(_NativeFramework.Filename)%(_NativeFramework.Extension)" />
Expand Down
Loading