0

我将我的 Visual Studio 2010 更新到版本 10.0.30319.1 RTM Rel 并在构建过程中开始出现以下异常:

System.NullReferenceException:对象引用未设置为对象的实例。在 Microsoft.Silverlight.Build.Tasks.CompileXaml.LoadAssemblies(ITaskItem[] ReferenceAssemblies) 在 Microsoft.Silverlight.Build.Tasks.CompileXaml.get_GetXamlSchemaContext() 在 Microsoft.Silverlight.Build.Tasks.CompileXaml.GenerateCode(ITaskItem item, Boolean isApplication ) 在 Microsoft.Silverlight.Build.Tasks.CompileXaml.Execute() 在 Bohr.Silverlight.BuildTasks.BohrCompileXaml.Execute()

BohrCompileXaml.Execute 的代码如下:

     public override bool Execute() {
        List<TaskItem> pages = new List<TaskItem>();
        foreach (ITaskItem item in SilverlightPages) {
            string newFileName = getGeneratedName(item.ItemSpec);
            String content = File.ReadAllText(item.ItemSpec);
            String parentClassName = getParentClassName(content);
            if (null != parentClassName) {
                content = content.Replace("<UserControl", "<" + parentClassName);
                content = content.Replace("</UserControl>", "</" + parentClassName + ">");
                content = content.Replace("bohr:ParentClass=\"" + parentClassName + "\"", "");
            }
            File.WriteAllText(newFileName, content);
            pages.Add(new TaskItem(newFileName));
        }

        if (null != SilverlightApplications) {
            foreach (ITaskItem item in SilverlightApplications) {
                Log.LogMessage(MessageImportance.High, "Application: " + item.ToString());
            }
        }

        foreach (ITaskItem item in pages) {
            Log.LogMessage(MessageImportance.High, "newPage: " + item.ToString());
        }


        CompileXaml xamlCompiler = new CompileXaml();
        xamlCompiler.AssemblyName = AssemblyName;
        xamlCompiler.Language = Language;
        xamlCompiler.LanguageSourceExtension = LanguageSourceExtension;
        xamlCompiler.OutputPath = OutputPath;
        xamlCompiler.ProjectPath = ProjectPath;
        xamlCompiler.RootNamespace = RootNamespace;
        xamlCompiler.SilverlightApplications = SilverlightApplications;
        xamlCompiler.SilverlightPages = pages.ToArray();
        xamlCompiler.TargetFrameworkDirectory = TargetFrameworkDirectory;
        xamlCompiler.TargetFrameworkSDKDirectory = TargetFrameworkSDKDirectory;
        xamlCompiler.BuildEngine = BuildEngine;
        bool result = xamlCompiler.Execute(); // HERE we got the error!  

以及任务的定义:

        <BohrCompileXaml 
           LanguageSourceExtension="$(DefaultLanguageSourceExtension)"
           Language="$(Language)" 
           SilverlightPages="@(Page)" 
           SilverlightApplications="@(ApplicationDefinition)" 
           ProjectPath="$(MSBuildProjectFullPath)"
           RootNamespace="$(RootNamespace)"
           AssemblyName="$(AssemblyName)" 
           OutputPath="$(IntermediateOutputPath)"
           TargetFrameworkDirectory="$(TargetFrameworkDirectory)" 
           TargetFrameworkSDKDirectory="$(TargetFrameworkSDKDirectory)"
           >

        <Output ItemName="Compile" TaskParameter="GeneratedCodeFiles" />

        <!-- Add to the list list of files written. It is used in Microsoft.Common.Targets to clean up 
             for a next clean build 
          -->
        <Output ItemName="FileWrites" TaskParameter="WrittenFiles" />
        <Output ItemName="_GeneratedCodeFiles" TaskParameter="GeneratedCodeFiles" />

    </BohrCompileXaml>

可能是什么原因?以及如何获得更多信息 CompileXaml 类中发生了什么?

4

1 回答 1

0

我的第一个猜测是参数ReferenceAssemblies为空。ReferenceAssemblies用于XamlSchemaContext进入CompileTask

要使其发挥作用,您有两种选择:

  • 将属性设置SkipLoadingAssembliesInXamlCompilertrue
  • 或者在属性中传递一个程序集路径ReferenceAssembliesmscorlib.dll 或另一个 silverlight dll

更简单的是将属性设置SkipLoadingAssembliesInXamlCompilertrue. 为此,请修改您的BohrCompileXaml任务:

CompileXaml xamlCompiler = new CompileXaml();
...
xamlCompiler.SkipLoadingAssembliesInXamlCompiler = true;
于 2010-05-12T12:25:08.220 回答