Project targeting .NET Framework version 4.5.1 to

2019-09-08 07:43发布

I'm a beginner and I developed a working project in C# using Visual Studio. I targeted the project for .NET Framework version 4.5.1 and it works fine. Since it is written in C# I would like to extend it in order to make it work on every Windows device

The problem I'm facing is the following. In my original project I had:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Media; // for playing sounds
using System.Reflection;
using System.Resources;
using System.Threading;
using System.Windows.Forms;
using System.Runtime.InteropServices;

and they gave no problems. If I put the same lines in the Windows Universal Platform version when I build the new solution I have for example [I'll put just two errors among the many ones]:

Error CS0234 The type or namespace name 'Drawing' does not exist in the namespace 'System' (are you missing an assembly reference?) TestProgram C:\Users\Antonino\documents\visual studio2015\Projects\TestProgram\TestProgram\MainPage.xaml.cs 6

Error CS0246 The type or namespace name 'ToolStripMenuItem' could not be found (are you missing a using directive or an assembly reference?) TestProgram C:\Users\Antonino\documents\visual studio 2015\Projects\TestProgram\TestProgram\MainPage.xaml.cs 80

Is there a smart way to have these missing files recognized in a simple way even when developing the universal Windows app? please don't tell me that I have to rewrite the whole project

Thanks in advance to those who will try to help,
Antonino

1条回答
Lonely孤独者°
2楼-- · 2019-09-08 08:21

the issue here isn't the framework version but rather the reduced framework API that is available to Universal Apps. Windows Universal apps don't have the same coverage of namespaces, classes, and APIs as the full .NET framework, and as a result, you can't reuse everything from full .net (such as System.Drawing) in a Universal Project.

However, you don't necessarily have to rewrite the WHOLE THING. instead, what you want to do is abstract the platform-specific behavior to an interface, and only that part has to be rewritten.

in otherwords, the global behaviors, UI and interaction can be reused using the classes available in all frameworks, usually represented by a Portable Class Library (PCL), and each version of your app (Winforms, Universal, Xamarin, etc) would reuse that shared library for the "core" of the application and the UI (and platform-specific behavior) would be the only part you would implement separately, in each version of the app you want to support.

I'm not sure if this answers your question entirely, but I do hope this was helpful.

查看更多
登录 后发表回答