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

Can't seem to use #if in Cross-Platform Library #3932

Closed
1 of 23 tasks
stefanolson opened this issue Sep 2, 2020 · 3 comments
Closed
1 of 23 tasks

Can't seem to use #if in Cross-Platform Library #3932

stefanolson opened this issue Sep 2, 2020 · 3 comments
Labels
kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification

Comments

@stefanolson
Copy link

Current behavior

Error CS0234: The type or namespace name 'Data' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

When using #if to share code with a WPF project in a Cross-Platform Library. System.Windows is WPF code that the compiler should be ignoring

Expected behavior

Compile with no issues.

How to reproduce it (as minimally and precisely as possible)

Create a new uno project. Within the project create a new 'Cross-Platform Library'. In the class library class, insert the following code:
`using System;
#if UNO_1213
using Windows.UI.Xaml.Data;
#else
using System.Windows.Data;
using System.Windows;
#endif

namespace ClassLibrary
{
public class Class1:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
    throw new NotImplementedException();
}

}
}

In the Properties for the class library project define a conditional symbol of UNO_1213. Visual Studio doesn't seem to know that UNO_1213 is defined because IValueConverter remains red - yet Windows.UI.Xaml.Data is not grayed out. So it obviously understands it's turned on to some extent. If I change the #if to something else it does become grayed out:
image

Sample project including msbuild.binlog enclosed

Workaround

None so far

Environment

Nuget Package:

  • Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia
  • Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia
  • Uno.SourceGenerationTasks
  • Uno.UI.RemoteControl / Uno.WinUI.RemoteControl
  • Other:

Nuget Package Version(s):

Affected platform(s):

  • iOS
  • Android
  • WebAssembly
  • WebAssembly renderers for Xamarin.Forms
  • macOS
  • Skia
    • WPF
    • GTK (Linux)
  • Windows
  • Build tasks
  • Solution Templates

IDE:

  • Visual Studio 2017 (version: )
  • Visual Studio 2019 (version: 16.7.2)
  • Visual Studio for Mac (version: )
  • Rider Windows (version: )
  • Rider macOS (version: )
  • Visual Studio Code (version: )

Relevant plugins:

  • Resharper (version: )

UnoTester.zip

@stefanolson stefanolson added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels Sep 2, 2020
@davidjohnoliver
Copy link
Contributor

Thanks for the report!

Looking at the .csproj file in your repro, this is arising because the conditional symbol is only defined for the UWP target:

  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|uap10.0.18362|AnyCPU'">
    <DefineConstants>UNO_1213</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|uap10.0.18362|AnyCPU'">
    <DefineConstants>UNO_1213</DefineConstants>
  </PropertyGroup>

therefore it's failing to build for the other targets.

If you replace the above in ClassLibrary.csproj with

  <PropertyGroup>
    <DefineConstants>UNO_1213</DefineConstants>
  </PropertyGroup>

all targets should build successfully.

@stefanolson
Copy link
Author

Thanks! Build now works. Hopefully visual studio will improve their tooling to keep up with the capabilities of the uno platform!

@jeromelaban
Copy link
Member

Indeed. The fact that .NET 5 will be more on the cross-targeting side that previously will help a lot for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification
Projects
None yet
Development

No branches or pull requests

3 participants