2016-05-09 18 views
-1

MarkupCompilePass1を使用してxamlbamlをコンパイルしています。これは、baml/xamlリソースを指す相対パスの他に、かなりうまく機能しています。MarkupCompilePass1を使用してbaml/xamlの相対パスを設定します。

_contentLoaded = true; 
System.Uri resourceLocater = new System.Uri("/Sample01;component/ui/controls/test.xaml", System.UriKind.Relative); 

#line 1 "test.xaml" 
System.Windows.Application.LoadComponent(this, resourceLocater); 

しかし、それは現在、次のようになります:

_contentLoaded = true; 
System.Uri resourceLocater = new System.Uri("/Sample01;component/test.xaml", System.UriKind.Relative); // <--- Here is the problem 

#line 1 "test.xaml" 
System.Windows.Application.LoadComponent(this, resourceLocater); 

がどのように解決することができます例えば者は、生成されたコード(test.g.cs)は次のようになりますよりも、XAMLファイルは、ディレクトリui/controls/test.xamlであると仮定しましょうこの問題? /ui/controlsが含まれていないため、Uriは完全ではありません。

ここでEDIT 1

baml*.g.cs

foreach (var _xaml in xamlSources) 
{ 
    // Relative path to the xaml file 
    _xaml.RelativePath = _xaml.RelativePath = Path.GetDirectoryName(_xaml.Path.Replace(CXUIBuildEngine.ProjectRoot, "")); 

    _task = new MarkupCompilePass1(); 
    _task.BuildEngine = BuildEngine; 
    _task.RequirePass2ForMainAssembly = false; 
    _task.OutputType = "library"; 

    // List of xaml to compile, im this case just one, 
    // because only one output is allowed so we have to set 
    // the specific output per compile process... 
    _task.PageMarkup = new[] { new XamlItem(_xaml.Path) }; 

    // Set default namespace 
    if (!string.IsNullOrWhiteSpace(CXUIBuildEngine.RootNamespace)) 
    { 
     _task.RootNamespace = CXUIBuildEngine.RootNamespace; 
    } 

    // Set default options 
    _task.AssemblyName = CXUIBuildEngine.AssemblyName; 
    _task.Language = "cs"; 

    // !!! Here we combine the output path with the relative path, 
    // !!! This is maybe already the fault 
    _task.OutputPath = Path.Combine(TempOutputDirectory, _xaml.RelativePath); 

    // Add all references as XamlItem 
    if (CXUIBuildEngine.References != null) 
    { 
     _task.References = CXUIBuildEngine.References.Select(item => new XamlItem(item.Location)).ToArray(); 
    } 

    if (!_task.Execute()) 
    { 
     return false; 
    } 
} 

はあなたにたくさんありがとうござい生成し、現在のコードです! XamlPages/ItemsLinkLogicalNameを設定

+0

* "MarkupCompilePass1'を使用して' xaml'を 'baml'にコンパイルしています" * - あなたはそれをやっていることを示すことができますか?私には、root(base)フォルダがxamlのどこにあるかのようにファイルをコンパイルしているようです。プロジェクトのルート(ベース)フォルダを使用してコンパイルする必要があります。その後、適切なパスが生成されます。 – Sinatr

+0

@Sinatrジェネレータコードを追加しました。これは役に立ちますか?あなたの答えをありがとう! – BendEg

+0

'OutputPath'がどのように見えるかを調べ、そこに相対パスを使用しようとします。 – Sinatr

答えて

0

は助けるようだ:

var _item = new XamlItem(_xaml.Path); 
_item.SetMetadata("Link", _xaml.RelativePath + "\\" + Path.GetFileName(_xaml.Path)); 
_item.SetMetadata("LogicalName", _xaml.RelativePath + "\\" + Path.GetFileName(_xaml.Path)); 
_task.PageMarkup = new[] { _item }; 

このプロパティは、項目だけのDictioary<string, string>内部に保存されます。

関連する問題