Skip to content

Commit

Permalink
Merge pull request #82 from jnm2/wpf_workaround
Browse files Browse the repository at this point in the history
Workaround to provide nullability attributes to WPF temp projects
  • Loading branch information
sharwell authored Jul 30, 2020
2 parents 000203e + 509b24b commit 05b952d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<ItemGroup Condition="'$(GenerateNullableAttributes)' == 'true' AND Exists($(NullableAttributesPath))">
<Compile Include="$(NullableAttributesPath)" Visible="false" />

<!-- Workaround for https://github.com/dotnet/wpf/issues/810 -->
<_GeneratedCodeFiles Include="$(NullableAttributesPath)" Visible="false" Condition="'$(UseWPF)' == 'true'" />

<!-- Make sure the source file is embedded in PDB to support Source Link -->
<EmbeddedFiles Condition="'$(DebugType)' != 'none'" Include="$(NullableAttributesPath)" />
</ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ test_script:
- msbuild /restore tests/SingleTFM /p:TestFramework=netcoreapp3.0 /warnaserror /nr:false /v:m
- git clean -dxf tests
- msbuild /restore tests/SingleTFM /p:TestFramework=netcoreapp3.1 /warnaserror /nr:false /v:m
- git clean -dxf tests
- msbuild /restore tests/WPF /warnaserror /nr:false /v:m

- git clean -dxf tests
- dotnet msbuild -restore tests/MultiTFM -warnaserror -nr:false -v:m
Expand Down Expand Up @@ -70,5 +72,7 @@ test_script:
- dotnet msbuild -restore tests/SingleTFM -p:TestFramework=netcoreapp3.0 -warnaserror -nr:false -v:m
- git clean -dxf tests
- dotnet msbuild -restore tests/SingleTFM -p:TestFramework=netcoreapp3.1 -warnaserror -nr:false -v:m
- git clean -dxf tests
- dotnet msbuild -restore tests/WPF -warnaserror -nr:false -v:m
artifacts:
- path: 'TunnelVisionLabs.ReferenceAssemblyAnnotator\**\*.nupkg'
12 changes: 12 additions & 0 deletions tests/WPF/UserControl1.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<UserControl x:Class="WPF.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WPF"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>

</Grid>
</UserControl>
25 changes: 25 additions & 0 deletions tests/WPF/UserControl1.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Controls;

namespace WPF
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}

public static void M(SqlConnection connection, [AllowNull] string? x)
{
if (!string.IsNullOrEmpty(x))
{
x.ToString();
}

_ = EqualityComparer<string?>.Default.GetHashCode(x);
}
}
}
19 changes: 19 additions & 0 deletions tests/WPF/WPF.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<!-- Using net40 instead of net35. jnm2.ReferenceAssemblies.net35 isn't automatically referenced by the .NET Core SDK like
Microsoft.NETFramework.ReferenceAssemblies is, and therefore it doesn't provide assemblies to the WPF temp assembly project. -->
<TargetFrameworks>net40;net48;netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
<UseWPF>true</UseWPF>
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
<NoWarn>RA1000</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Condition="'$(TargetFramework)' != 'net40'" Include="System.Data.SqlClient" Version="4.8.0" />
<PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.*" PrivateAssets="all" />
<PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[3.1.0]" />
</ItemGroup>

</Project>

0 comments on commit 05b952d

Please sign in to comment.