【问题标题】:Building WP8.0 assembly from code从代码构建 WP8.0 程序集
【发布时间】:2014-09-02 15:42:12
【问题描述】:

我正在尝试用代码构建一个 WP 8.0 项目。我正在使用 Project 类和 Build 方法,源代码可用here

代码在使用 VS 2012 的 Windows 8 上运行,但是当我升级到 Windows 8.1 和 VS2013 时,它停止工作。我知道微软在 VS 中从 .NET 中更改并删除了 Build 框架,但我仍然不确定它为什么会发生以及如何修复它。

错误:

C:\程序文件 (x86)\MSBuild\Microsoft\WindowsPhone\v8.0\Microsoft.WindowsPhone.Common.targets(75,5): 错误 MSB4127:无法执行“GetSilverlightFrameworkPath”任务 从程序集“C:\Program Files (x86)\MSBuild\Microsoft\WindowsPhone\v8.0\Microsoft.Silverlight.WindowsPhone.Build.Tasks.dll"。 请验证任务程序集是否已使用相同版本构建 Microsoft.Build.Framework 程序集作为安装在您的 计算机并且您的主机应用程序没有缺少绑定 Microsoft.Build.Framework 的重定向。无法转换类型的对象 'Microsoft.Silverlight.Build.Tasks.GetSilverlightFrameworkPath' 到 键入“Microsoft.Build.Framework.ITask”.C:\Program Files (x86)\MSBuild\Microsoft\WindowsPhone\v8.0\Microsoft.WindowsPhone.Common.targets(75,5): 错误 MSB4060:“GetSilverlightFrameworkPath”任务已 声明或使用不正确,或在构建过程中失败。检查 任务名称和程序集名称的拼写。

更新: 顺便说一句,WP 8.0 是使用 VS2013 编译的,尝试从代码构建它时会出现问题。

【问题讨论】:

    标签: msbuild visual-studio-2013 windows-phone


    【解决方案1】:

    您收到此错误是因为 Microsoft.Silverlight.WindowsPhone.Build.Tasks.dll 是包含 GetSilverlightFrameworkPath 的程序集,例如在 Silverlight 4 和 5 SDK 中:

    // Decompiled with JetBrains decompiler
    // Type: Microsoft.Silverlight.Build.Tasks.GetSilverlightFrameworkPath
    // Assembly: Microsoft.Silverlight.Build.Tasks, Version=9.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
    // MVID: 2E9B62C4-1C0C-4AAD-8CBE-F7E074602879
    // Assembly location: C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v5.0
    
    //omitted for brevity
    
    namespace Microsoft.Silverlight.Build.Tasks
    {
      public sealed class GetSilverlightFrameworkPath : Task
      {
        private const string SDKAssemblyFoldersExRegKey = "v5.0\\AssemblyFoldersEx";
        public const string SDKLibrariesRegKey = "v5.0\\AssemblyFoldersEx\\Silverlight SDK Client Libraries";
        public const string SDKRuntimeInstallPathRegKey = "SOFTWARE\\Microsoft\\Microsoft SDKs\\Silverlight\\v5.0\\ReferenceAssemblies";
    
        public string RegistryBase { get; set; }
    
        public string SilverlightPath { get; set; }
    
        public string[] SilverlightSDKPaths { get; set; }
    
        public string SilverlightRuntimeVersion { get; set; }
    
        public override bool Execute()
        {
          //omitted for brevity
        }
    
        private string GetSilverlightPath()
        {
          //omitted for brevity
        }
    
        private string GetSDKRuntimeVersion()
        {
          //omitted for brevity
        }
    
        private string[] GetAllSilverlightSDKPaths()
        {
          //omitted for brevity
        }
      }
    }
    

    然而,它在 WP v8.0 中的实现似乎确实有很大不同:

    // Decompiled with JetBrains decompiler
    // Type: Microsoft.Silverlight.Build.Tasks.GetSilverlightFrameworkPath
    // Assembly: Microsoft.Silverlight.WindowsPhone.Build.Tasks, Version=9.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
    // MVID: 899BFFD0-786C-472A-8935-576EED0F4F90
    // Assembly location: C:\Program Files (x86)\MSBuild\Microsoft\WindowsPhone\v8.0\Microsoft.Silverlight.WindowsPhone.Build.Tasks.dll
    
    //omitted for brevity
    
    namespace Microsoft.Silverlight.Build.Tasks
    {
      public sealed class GetSilverlightFrameworkPath : Task
      {
        public string RegistryBase { get; set; }
    
        public string RuntimePathRegistryKey { get; set; }
    
        public string RuntimeVersionRegistryKey { get; set; }
    
        public string AdditionalRegistryBasePaths { get; set; }
    
        public string SilverlightPath { get; set; }
    
        public string[] SilverlightSDKPaths { get; set; }
    
        public string SilverlightRuntimeVersion { get; set; }
    
        public override bool Execute()
        {
             // omitted for brevity
        }
    
        private string GetSilverlightPath()
        {
          // omitted for brevity
        }
    
        private string GetSDKRuntimeVersion()
        {
          // omitted for brevity
        }
    
        internal string[] GetAllSilverlightSDKPaths()
        {
          // omitted for brevity
        }
    }
    

    因此,事情不起作用是很自然的。

    您需要做的是检查您在所有项目中是否引用了相同的 SDK 版本。

    您在构建期间尝试实例化的任务位于 SL SDK 5 中,而目前由于某种原因构建过程正在尝试使用 WP8.0 SDK。

    此外,您引用的代码是 references Toolset 12.0 的 csproj 的一部分:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    

    你确定这是想要的吗?

    This info 也可能与您有关。

    如果您提供有关实际项目的更多信息,它可能很容易修复。现在,要判断一切是如何设置的有点困难。

    【讨论】:

    • 抱歉回复晚了。我认为我希望我的所有项目都使用新的工具版本(12.0)。但如果它没有它也能工作......我会很高兴。您可以尝试导入项目并使用“-s 1 -v 1.9.0 -l true”配置运行 Google.Apis.Release。我正在处理我仍然没有得到的问题......我会尝试更多时间调查它,但它看起来很奇怪。
    猜你喜欢
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-25
    • 1970-01-01
    • 2011-10-21
    • 1970-01-01
    相关资源
    最近更新 更多