无法在发布模式下构建 UWP [英] Can't build UWP in release mode

查看:32
本文介绍了无法在发布模式下构建 UWP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目在调试模式下运行良好,但在发布模式下根本无法运行.

I have a project that is working well in debug mode, but not working at all in release mode.

解决方案包含 3 个项目

The solution contains 3 projects

  • 共享项目

  • Shared project

windows phone 8.1 项目

windows phone 8.1 project

UWP 项目

这里是错误输出

 2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : System.InvalidOperationException: Unable to generate a temporary class (result=1).
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : error CS0012: The type 'Windows.UI.Xaml.Visibility' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows.Foundation.UniversalApiContract, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : error CS0030: Cannot convert type 'Windows.UI.Xaml.Visibility' to 'Windows.UI.Xaml.Visibility [e:\MyApp\obj\x86\Release\ilc\in\WinMetadata\Windows.winmd]'
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : error CS0029: Cannot implicitly convert type 'Windows.UI.Xaml.Visibility [e:\MyApp\obj\x86\Release\ilc\in\WinMetadata\Windows.winmd]' to 'Windows.UI.Xaml.Visibility'
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : 
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error :    at System.Xml.Serialization.Compiler.Compile(String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence, String outputDir, String intermediateDir, Boolean loadAssembly)
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error :    at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Hashtable assemblies, String outputDir, String intermediateDir, Boolean loadAssembly)
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error :    at System.Xml.Serialization.XmlSerializer.GenerateSerializer(Type[] types, XmlMapping[] mappings, CompilerParameters parameters, String outputDir, String intermediateDir, Boolean loadAssembly)
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error :    at System.Xml.Serialization.XmlSerializer.GenerateSerializer(Type[] types, String outputDir, String intermediateDir, List`1 wcfSerializers, Boolean loadAssembly)
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error :    at SerializationAssemblyGenerator.Program.Main(String[] args)
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : Internal compiler error: One or more errors occurred.

我使用的 nuget 包是

The nuget packages I'm using are

    "GoogleAnalyticsSDK": "1.2.12",
    "HockeySDK.UWP": "4.0.0",
    "HtmlAgilityPack": "1.4.9",
    "Microsoft.ApplicationInsights": "1.0.0",
    "Microsoft.ApplicationInsights.PersistenceChannel": "1.0.0",
    "Microsoft.ApplicationInsights.WindowsApps": "1.0.0",
    "Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
    "MvvmLightLibs": "5.1.1",
    "Newtonsoft.Json": "8.0.3",
    "WriteableBitmapEx": "1.5.0"

更新

我尝试手动添加 Windows.Foundation.UniversalApiContract,但得到了这个

I tried to add the Windows.Foundation.UniversalApiContract manually, but got this

更新 2

在我取消选中 Compile with .Net Native 工具链功能后,它起作用了.

After I have unchecked the Compile with .Net Native tool chain feature, it worked.

任何使用 .net 原生工具链构建它的方法?

Any way to build it using the .net native tool chain ?

推荐答案

我也遇到了一个非常相似的问题.我有一个类型,比如说 Foo,引用了一个 winmd 类型 Windows.UI.Xaml.Visibility,见下文.

I also hit a very similar issue. I had a type, let's say Foo, referencing a winmd type Windows.UI.Xaml.Visibility, see below.

    public class Foo
    {
        public Windows.UI.Xaml.Visibility Visibility;
    }

当我尝试使用 XmlSerializer 序列化 Foo 类型的实例时,我在编译时遇到了完全相同的错误..Net Native 工具似乎在为 Foo 等类型生成 XmlSerializer 时遇到问题.

I got the exact same error at compile time when I tried to serialize an instance of type Foo using XmlSerializer. It seems that .Net Native tools have problem with generating XmlSerializer for types like Foo.

这是我的解决方法.我创建了自己的可见性类型 MyVisibility,并将现有的可见性字段更改为仅获取属性(以便 XmlSerializer 不会序列化该属性).

Here's my workaround. I created my own Visibility type, MyVisibility, and changed the existing Visibility field to a get only property (so that XmlSerializer would not serialize the property).

    public class Foo
    {
        public Windows.UI.Xaml.Visibility Visibility
        {
            get
            {
                return (Visibility)myVisibility;
            }
        }

        public MyVisibility myVisibility;
    }

    public enum MyVisibility
    {
        Visible = 0,
        Collapsed = 1
    }

这是我用于序列化 Foo 实例的测试代码,

Here's my test code for serializing a Foo instance,

    public static void Test()
    {
        var foo = new Foo();
        foo.myVisibility = MyVisibility.Collapsed;            
        var serializer = new XmlSerializer(typeof(Foo));
        using (var stream = new MemoryStream())
        {
            serializer.Serialize(stream, foo);
            stream.Position = 0;
            var foo1 = (Foo)serializer.Deserialize(stream);
            Assert.True(foo.Visibility == foo1.Visibility);
        }
    }

希望这会有所帮助.

这篇关于无法在发布模式下构建 UWP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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