面向 .NET Framework 4.5.1 版到通用 Windows 10 的项目 [英] Project targeting .NET Framework version 4.5.1 to Universal Windows 10

查看:30
本文介绍了面向 .NET Framework 4.5.1 版到通用 Windows 10 的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是初学者,我使用 Visual Studio 用 C# 开发了一个工作项目.我针对 .NET Framework 版本 4.5.1 的项目,它工作正常.由于它是用 C# 编写的,因此我想对其进行扩展以使其适用于所有 Windows 设备

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;

他们没有给任何问题.如果我在构建新解决方案时在 Windows 通用平台版本中放置相同的行,例如[我将在许多错误中只列出两个错误]:

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]:

错误 CS0234 命名空间系统"中不存在类型或命名空间名称绘图"(您是否缺少程序集引用?)TestProgram C:\Users\Antonino\documents\visual studio2015\Projects\TestProgram\TestProgram\MainPage.xaml.cs 6

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

错误 CS0246 找不到类型或命名空间名称ToolStripMenuItem"(您是否缺少 using 指令或程序集引用?)TestProgram C:\Users\Antonino\documents\visual studio 2015\Projects\TestProgram\TestProgram\MainPage.xaml.cs 80

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

即使在开发通用 Windows 应用程序时,是否也有一种聪明的方法可以以简单的方式识别这些丢失的文件?请不要告诉我必须重写整个项目

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

推荐答案

这里的问题不是框架版本,而是通用应用程序可用的简化框架 API.Windows 通用应用的命名空间、类和 API 覆盖范围与完整 .NET 框架不同,因此,您无法在通用项目中重用完整 .net(例如 System.Drawing)中的所有内容.

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.

换句话说,可以使用所有框架中可用的类重用全局行为、UI 和交互,这些类通常由可移植类库 (PCL) 和应用程序的每个版本(Winforms、Universal、Xamarin 等)表示会将该共享库重用于应用程序的核心",而 UI(和特定于平台的行为)将是您在要支持的每个应用程序版本中单独实施的唯一部分.

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.

这篇关于面向 .NET Framework 4.5.1 版到通用 Windows 10 的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆