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

Cannot update from 1.5.4 or use in VS2019 #167

Closed
MichaelRumpler opened this issue May 31, 2019 · 14 comments
Closed

Cannot update from 1.5.4 or use in VS2019 #167

MichaelRumpler opened this issue May 31, 2019 · 14 comments

Comments

@MichaelRumpler
Copy link

I changed several projects to use one multi-targeting project last year. Back then I used MSBuild.Sdk.Extras 1.5.4 in VS2017 and it worked like a charm.

But now I want to use VS2019 and I ran into several different issues.
My problems with VS2019 are described in dotnet/project-system#4889.
But it looks more like this package is the problem.

I already read https://github.com/onovotny/MSBuildSdkExtras#migrate-from-the-old-way-vs-pre-156, but I need to compile that project for many different platforms including Xamarin.Mac20, uap10.0.16299 and net461. The former only works on Mac and the two others only on Windows.
Your migration description indicates, that I have to stay with the PackageReference when I need it in VS4Mac.

I did try to update to 2.0.24 on Windows using

<Project Sdk="MSBuild.Sdk.Extras/2.0.24">

but then I got:

C:\Program Files\dotnet\sdk\3.0.100-preview5-011568\Sdks\MSBuild.Sdk.Extras\Sdk not found. Check that a recent enough .NET Core SDK is installed and/or increase the version specified in global.json.

and

D:\MR.Gestures\MR.Gestures\MR.Gestures.csproj : error NU1202: Package System.Numerics.Vectors.WindowsRuntime 4.0.1 is not compatible with netcore50 (.NETCore,Version=v5.0). Package System.Numerics.Vectors.WindowsRuntime 4.0.1 supports: uap10.0 (UAP,Version=v10.0)

I don't have a global.json, that's why I added the version in the Sdk.

I also tried to update only to the very next version after 1.5.4;1.6.19-preview, but then VS2017 seems to have problems finding the correct framework.

image

It tries to compile a class which is only for WPF in the project MR.Gestures (MonoAndroid81)

But when I open that file, the dropdown for the platform is correct.

image

Here are the relevant parts of my csproj file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
	<TargetFrameworks>netstandard1.0;netstandard2.0;Xamarin.iOS10;MonoAndroid81;uap10.0.16299;net461</TargetFrameworks>
	<!--Work around so the conditions work below-->
<!--
	<TargetFrameworks></TargetFrameworks>
	<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">netstandard1.0;netstandard2.0;Xamarin.iOS10;MonoAndroid81;uap10.0.16299;net461</TargetFrameworks>
	<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">Xamarin.Mac20;netstandard1.0;netstandard2.0;Xamarin.iOS10;MonoAndroid81</TargetFrameworks>
-->

  </PropertyGroup>

  <ItemGroup>
	<PackageReference Include="MSBuild.Sdk.Extras" Version="1.6.19-preview" PrivateAssets="All" />
	<PackageReference Include="Xamarin.Forms" Version="4.0.0.425677" />
	<Compile Include="All\**\*.cs" />
  </ItemGroup>

  <ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">
	<PackageReference Include="Xamarin.Forms.Platform.WPF" Version="4.0.0.425677" />
	<Compile Include="WPF\**\*.cs" />
  </ItemGroup>

  <ItemGroup>
	<None Include="**/*" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);$(Compile)" />
  </ItemGroup>

  <Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
</Project>

The first TargetFrameworks line is just for testing now. I actually want to use the lines which are now commented out.

The whole file is in dotnet/project-system#4889

@clairernovotny
Copy link
Collaborator

Unfortunately, 1.x will not work in VS 2019 due to changes in MSBuild file locations. You do need 2.x for that.

The UWP issue is this bug and the fix will be in 16.1.2 (which isn't out yet): dotnet/project-system#4854

What versions of the .NET Core SDK do you have? (dotnet --info)?

@MichaelRumpler
Copy link
Author

Can I use 2.x in VS4mac?

I have Core 3.0.100-preview5-011568.

@clairernovotny
Copy link
Collaborator

See #168 (comment)

@MichaelRumpler
Copy link
Author

So you're saying 2.x is required for VS2019, but it does not work currently. VS 16.1.2 should fix it.

I know that VS4Mac only builds the first target framework, but I'm fine with that as I build the others on Windows. Currently I build all platforms but Xamarin.Mac20 on Windows, then build that on the Mac, copy the result over to Windows and then do nuget pack on Windows to include all platforms.

@jamesmontemagno
Copy link

Everything should work with 2.0.29, I just tested with Xamarin.Essentials and looks like it is better now. Need @onovotny to push to stable please :)

@clairernovotny
Copy link
Collaborator

@jamesmontemagno just pushed 2.0.29 to NuGet

@MichaelRumpler
Copy link
Author

MichaelRumpler commented Jun 14, 2019

I still cannot update it.

My VS has version 16.1.3 now. I tried to update to 2.0.29. The initial error when opening the solution is gone, but I can't compile the project. There are still errors because it tries to compile with the wrong platform.

VS claims that it can't find the FrameworkElement:
image
But it looks like it doesn't use the namespace System.Windows (the using is greyed out).

In the error list it looks like it wants to compile it for netstandard1.0 although that is not in the leftmost dropdown for the platform for the file.
image

From the Output window:

1>WPF\EventArgs\WPFDownUpEventArgs.cs(9,84,9,100): error CS0246: The type or namespace name 'FrameworkElement' could not be found (are you missing a using directive or an assembly reference?)

In other files (which are also in the WPF folder and should only be used for that platform) I also get errors like these:

error CS0012: The type 'Border' is defined in an assembly that is not referenced. You must add a reference to assembly 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

My .csproj looks like this (only relevant parts included):

<Project Sdk="MSBuild.Sdk.Extras/2.0.29">

  <PropertyGroup>
	<TargetFrameworks>netstandard1.0;netstandard2.0;Xamarin.iOS10;MonoAndroid81;uap10.0.16299;net461</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
	<PackageReference Include="Xamarin.Forms" Version="4.0.0.425677" />
	<Compile Include="All\**\*.cs" />
  </ItemGroup>

  <ItemGroup Condition=" $(TargetFramework.StartsWith('netstandard')) ">
  </ItemGroup>

  <ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">
	<PackageReference Include="Xamarin.Forms.Platform.WPF" Version="4.0.0.425677" />
	<Compile Include="WPF\**\*.cs" />
  </ItemGroup>

  <ItemGroup>
	<None Include="**/*" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);$(Compile)" />
  </ItemGroup>
</Project>

The solution explorer doesn't show any dependency problems:
image

When I try to update MSBuild.Sdk.Extras via "Manage NuGet Packages for Solution", then I get

Package 'MSBuild.Sdk.Extras 2.0.29' has a package type 'MSBuildSdk' that is not supported by project 'GestureSample'.

Because you also asked for the .NET Core SDK before - I also updated that in the meantime to 3.0.100-preview6-012264. But the C:\Program Files\dotnet\sdk\3.0.100-preview6-012264\Sdks folder does not contain anything like MSBuild.Sdk.Extras*. Do I have to do anything special to download it or do I look in the wrong folder?

I don't know what @jamesmontemagno did to get it working. Unfortunately his update is not reflected in https://github.com/xamarin/Essentials/blob/master/Xamarin.Essentials/Xamarin.Essentials.csproj yet.

@clairernovotny
Copy link
Collaborator

clairernovotny commented Jun 14, 2019

You need to have the Project element look like this: <Project Sdk="MSBuild.Sdk.Extras/2.0.29"> (or <Project Sdk="MSBuild.Sdk.Extras"> if you put the Extras SDK version in the global.json as the docs describe:

{
  "sdk": {
    "version": "3.0.100-preview"
  },
  "msbuild-sdks": {
    "MSBuild.Sdk.Extras": "2.0.29"
  }
}

MSBuild will download the SDK from NuGet with either of those syntax options.

@MichaelRumpler
Copy link
Author

That's what I did. I already pasted parts of my csproj file above. Here is just the first line again:

<Project Sdk="MSBuild.Sdk.Extras/2.0.29">

I never had a global.json file.

@jamesmontemagno
Copy link

You can look at what I have done here: xamarin/Essentials#813

@MichaelRumpler
Copy link
Author

MichaelRumpler commented Jun 15, 2019

I did the same as James. However, Xamarin.Essentials does not target WPF and my problems are with WPF.

Here is a repro project. It uses my project structure, but with almost no content. Every platform has one class which uses a platform specific view.
Repro.MSBuildSdkExtras.zip

Repro.MSBuildSdkExtras.sln/.csproj uses MSBuild.Sdk.Extras 2.0.29
Repro.MSBuildSdkExtras_old.sln/.csproj uses MSBuild.Sdk.Extras 1.5.4

When I build the old version in VS2017, then it succeeds.
When I try to build the new one with VS2019 (16.1.3 or 16.2.0 Preview 2), I get this error:

WPF\WPFSomeClass.cs(9,38,9,54): error CS0234: The type or namespace name 'FrameworkElement' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

So it seems like the new MSBuild.Sdk.Extras does not include all references which version 1.5.4 included. I also see that in the solution explorer dependencies now.
Dependencies / .NETFramework 4.6.1 / Assemblies is missing PresentationCore, PresentationFramework, System.Xaml and WindowsBase. These were all shown in the solution explorer of VS2017 with Sdk.Extras 1.5.4.

How can I add these? When I do Add Reference, I only see the target .NET Standard 1.0.
image

@MichaelRumpler
Copy link
Author

I could add the missing references manually in the project file:

    <ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">
+      <Reference Include="System.Xaml">
+        <RequiredTargetFramework>4.0</RequiredTargetFramework>
+      </Reference>
+      <Reference Include="WindowsBase" />
+      <Reference Include="PresentationCore" />
+      <Reference Include="PresentationFramework" />
      <PackageReference Include="Xamarin.Forms.Platform.WPF" Version="4.0.0.425677" />
      <Compile Include="WPF\**\*.cs" />
    </ItemGroup>

With these changes, version 2.0.29 also works for me. However this was not required with 1.5.4. Whether this was a bug in the old or the current version lies in the eye of the beholder.

@clairernovotny
Copy link
Collaborator

clairernovotny commented Jun 18, 2019

@MichaelRumpler
Copy link
Author

I found that file in C:\Users\micha.nuget\packages\msbuild.sdk.extras\2.0.29\Build\Platforms, but it doesn't seem like it will be run during build.

I already attached my repro project above. Here is the binlog.
Repro.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants