Skip to content
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

Add .NET Core 3.0 target to Caliburn.Micro.Platform #626

Merged
merged 9 commits into from
Aug 15, 2019
19 changes: 13 additions & 6 deletions azure-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ steps:
displayName: Nuget Restore
inputs:
solution: '$(coreSolution)'
configuration: '$(buildConfiguration)'
msbuildArgs: '/t:Restore'
configuration: '$(buildConfiguration)'

- task: PowerShell@2
# Workaround for https://github.com/onovotny/MSBuildSdkExtras/issues/174
displayName: 'Resource.Designer workaround'
inputs:
targetType: 'inline'
script: 'New-Item -ItemType File -Path .\src\Caliburn.Micro.Core\obj\Release\MonoAndroid80\Resource.Designer.cs -Force'

- task: VSBuild@1
displayName: Build & Pack Core Solution
Expand All @@ -40,12 +47,12 @@ steps:
platform: '$(buildPlatform)'
msbuildArgs: '/t:Pack /p:JavaSdkDirectory="$(JAVA_HOME_8_X64)"'

- task: VSTest@2
- task: DotNetCoreCLI@2
displayName: Run Unit Tests
inputs:
testAssemblyVer2: 'bin\**\*.Tests.dll'
configuration: '$(buildConfiguration)'
platform: '$(buildPlatform)'
command: test
projects: '**/*Test*/*.csproj'
arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'

- task: NuGetCommand@2
displayName: Restore Setup Solution
Expand Down Expand Up @@ -83,4 +90,4 @@ steps:
displayName: Publish Package Artifacts
inputs:
pathToPublish: '$(build.artifactStagingDirectory)'
artifactName: Packages
artifactName: Packages
4 changes: 2 additions & 2 deletions samples/features/Features.UWP/Features.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<PackageCertificateKeyFile>Features.UWP_TemporaryKey.pfx</PackageCertificateKeyFile>
<RuntimeIdentifiers>win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot</RuntimeIdentifiers>
<PackageCertificateThumbprint>B7A25D83EAD631188A9505D2D7C411770734C52B</PackageCertificateThumbprint>
<PackageCertificateThumbprint>714bf81d767ae7aa7fcf3bb435b0804ad3eadb05</PackageCertificateThumbprint>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -268,4 +268,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseLatestPlatformSdk>true</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
<AndroidSupportedAbis>armeabi,armeabi-v7a,x86</AndroidSupportedAbis>
<AndroidSupportedAbis>armeabi-v7a,x86</AndroidSupportedAbis>
<AndroidStoreUncompressedFileExtensions />
<MandroidI18n />
<JavaMaximumHeapSize />
Expand Down
5 changes: 5 additions & 0 deletions src/Caliburn.Micro.Core/Caliburn.Micro.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<RootNamespace>Caliburn.Micro</RootNamespace>
</PropertyGroup>

<!-- Workaround for https://github.com/onovotny/MSBuildSdkExtras/issues/173 -->
<PropertyGroup Label="Android DesignTimeBuild error workaround">
<DesignTimeBuild>false</DesignTimeBuild>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net45'">
<AssemblyOriginatorKeyFile>.\..\Caliburn.Micro.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="System.Windows.Interactivity.WPF" Version="2.0.20525" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="Moq" Version="4.8.3" />
Expand All @@ -21,9 +22,6 @@
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System.Windows.Interactivity">
<HintPath>C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\.NETFramework\v4.5\Libraries\System.Windows.Interactivity.dll</HintPath>
</Reference>
<Reference Include="System.Xaml" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Caliburn.Micro.Platform/ActionMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void ElementLoaded(object sender, RoutedEventArgs e) {
}
else currentElement = context.View;

#if NET
#if NET || NETCORE
var binding = new Binding {
Path = new PropertyPath(Message.HandlerProperty),
Source = currentElement
Expand Down
2 changes: 1 addition & 1 deletion src/Caliburn.Micro.Platform/Bind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static void ModelWithoutContextChanged(DependencyObject d, DependencyPropertyCha
/// </summary>
/// <param name="dependencyObject">The ui to apply conventions to.</param>
/// <returns>Whether or not conventions are applied.</returns>
#if NET
#if NET || NETCORE
[AttachedPropertyBrowsableForTypeAttribute(typeof(DependencyObject))]
#endif
public static bool GetAtDesignTime(DependencyObject dependencyObject) {
Expand Down
2 changes: 1 addition & 1 deletion src/Caliburn.Micro.Platform/BindingScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static bool RemoveChildResolver(ChildResolver resolver) {
continue;
}

#if NET
#if NET || NETCORE
var childCount = (current is Visual || current is Visual3D)
? VisualTreeHelper.GetChildrenCount(current) : 0;
#else
Expand Down
19 changes: 13 additions & 6 deletions src/Caliburn.Micro.Platform/Caliburn.Micro.Platform.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<Project Sdk="MSBuild.Sdk.Extras">

<PropertyGroup>
<TargetFrameworks>net45;uap10.0.16299;Xamarin.iOS10;MonoAndroid80;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net45;uap10.0.16299;Xamarin.iOS10;MonoAndroid80;netstandard2.0;netcoreapp3.0</TargetFrameworks>
<PackageId>Caliburn.Micro</PackageId>
<Product>Caliburn.Micro</Product>
<RootNamespace>Caliburn.Micro</RootNamespace>
</PropertyGroup>

<!-- Workaround for https://github.com/onovotny/MSBuildSdkExtras/issues/173 -->
<PropertyGroup Label="Android DesignTimeBuild error workaround">
<DesignTimeBuild>false</DesignTimeBuild>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'Xamarin.iOS10' or '$(TargetFramework)' == 'MonoAndroid80'">
<DefineConstants>XFORMS</DefineConstants>
</PropertyGroup>
Expand All @@ -28,7 +33,13 @@
<Reference Include="PresentationFramework" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
<Compile Include="Platforms\net46\**\*.cs" />
<Compile Include="Platforms\net46-netcore\**\*.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.0.1" />
<PackageReference Include="Microsoft.WindowsDesktop.App" Version="3.0.0-preview7-27912-14" />
<Compile Include="Platforms\net46-netcore\**\*.cs" />
</ItemGroup>

<ItemGroup Label="Package">
Expand Down Expand Up @@ -73,8 +84,4 @@
<Compile Include="ViewModelLocator.cs" />
</ItemGroup>

<ItemGroup>
<None Remove="Platforms\net46\AssemblyInfo.cs" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/Caliburn.Micro.Platform/ConventionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public static class ConventionManager {
/// Determines whether a custom update source trigger should be applied to the binding.
/// </summary>
public static Action<DependencyProperty, DependencyObject, Binding, PropertyInfo> ApplyUpdateSourceTrigger = (bindableProperty, element, binding, info) => {
#if WINDOWS_UWP || NET
#if WINDOWS_UWP || NET || NETCORE
binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
#endif
};
Expand Down Expand Up @@ -363,7 +363,7 @@ public static ElementConvention GetElementConvention(Type elementType) {
/// Determines whether a particular dependency property already has a binding on the provided element.
/// </summary>
public static bool HasBinding(FrameworkElement element, DependencyProperty property) {
#if NET
#if NET || NETCORE
return BindingOperations.GetBindingBase(element, property) != null;
#else
return element.GetBindingExpression(property) != null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Runtime.InteropServices;
using System.Windows.Markup;

[assembly: Guid("6449e9cb-4d4d-4d79-8f73-71a2fc647109")]
[assembly: XmlnsDefinition("http://www.caliburnproject.org", "Caliburn.Micro")]
[assembly: XmlnsPrefix("http://www.caliburnproject.org", "cal")]
[assembly: XmlnsDefinition("http://caliburnmicro.com", "Caliburn.Micro")]
[assembly: XmlnsPrefix("http://caliburnmicro.com", "cm")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
namespace Caliburn.Micro {
using System.Collections.Specialized;
using System.Linq;
using System.Windows;
using Microsoft.Xaml.Behaviors;

/// <summary>
/// A collection that can exist as part of a behavior.
/// </summary>
/// <typeparam name="T">The type of item in the attached collection.</typeparam>
public class AttachedCollection<T> : FreezableCollection<T>, IAttachedObject
where T : DependencyObject, IAttachedObject {
DependencyObject associatedObject;

/// <summary>
/// Creates an instance of <see cref="AttachedCollection{T}"/>
/// </summary>
public AttachedCollection() {
((INotifyCollectionChanged)this).CollectionChanged += OnCollectionChanged;
}

/// <summary>
/// Attached the collection.
/// </summary>
/// <param name="dependencyObject">The dependency object to attach the collection to.</param>
public void Attach(DependencyObject dependencyObject) {
WritePreamble();
associatedObject = dependencyObject;
WritePostscript();

this.Apply(x => x.Attach(associatedObject));
}

/// <summary>
/// Detaches the collection.
/// </summary>
public void Detach() {
this.Apply(x => x.Detach());
WritePreamble();
associatedObject = null;
WritePostscript();
}

DependencyObject IAttachedObject.AssociatedObject {
get { return associatedObject; }
}

/// <summary>
/// Called when an item is added from the collection.
/// </summary>
/// <param name="item">The item that was added.</param>
protected virtual void OnItemAdded(T item) {
if (associatedObject != null)
item.Attach(associatedObject);
}

/// <summary>
/// Called when an item is removed from the collection.
/// </summary>
/// <param name="item">The item that was removed.</param>
protected virtual void OnItemRemoved(T item) {
if(item.AssociatedObject != null)
item.Detach();
}

void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) {
switch(e.Action) {
case NotifyCollectionChangedAction.Add:
e.NewItems.OfType<T>().Where(x => !Contains(x)).Apply(OnItemAdded);
break;
case NotifyCollectionChangedAction.Remove:
e.OldItems.OfType<T>().Apply(OnItemRemoved);
break;
case NotifyCollectionChangedAction.Replace:
e.OldItems.OfType<T>().Apply(OnItemRemoved);
e.NewItems.OfType<T>().Where(x => !Contains(x)).Apply(OnItemAdded);
break;
case NotifyCollectionChangedAction.Reset:
this.Apply(OnItemRemoved);
this.Apply(OnItemAdded);
break;
}
}
}
}
Loading