Visual studio not copying content files from indirectly referenced project

前端 未结 5 662
滥情空心
滥情空心 2020-12-09 01:57

I have the following project structure:

Library1 <--[project reference]-- Library2 <--[ref]-- Executable
--------                          --------             


        
相关标签:
5条回答
  • 2020-12-09 02:12

    Add Library1 reference to the Executable project.

    0 讨论(0)
  • 2020-12-09 02:16

    One variation on Brenda's answer would be to add the Library1's content file(s) as Link(s) in the Executable project. You'd still have the entries in the project but you wouldn't need manage multiple copies of each file.

    0 讨论(0)
  • 2020-12-09 02:22

    Could be that you reference Library1 only from an XAML file in that case Visual Studio dont recognice the usage. Add a reference in code as well e.g. by applying the name attribute

    0 讨论(0)
  • 2020-12-09 02:25

    EDIT:

    You can put all content in a separate project, set all its entries to "content" and "copy always" and reference that project from External and Executable

    -

    IMO you're looking for embedded resource, not for content files.

    When you compile Library 1 the content files are placed in its bin folder. When Library 2 is compiled the compiler recognizes referenced code and includes it (Library 1.dll) but the content files aren't recognized since they aren't mentioned anywhere in Library 2. The same goes when linking Library 2 to the executable.

    If your content files are relatively small (icons, templates etc) and you don't envision need to edit them if you were to lose the source code then you can embed them as resources and provide a public method to return the contents, such as:

     public static Stream GetResourceContent(string rName){
         string resName = System.Reflection.Assembly
             .GetExecutingAssembly().GetManifestResourceNames()
             .FirstOrDefault(rn => rn.EndsWith("."+rName));
        if(resName!=null)
            return System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resName);
        else
            return null;
    }
    

    If your content is bound to change, such as templates etc, then consider including a copy with the executable project

    0 讨论(0)
  • 2020-12-09 02:33

    Another option would be to embed ContentFile as a resource inside the Library1 assembly and extract it using Assembly.GetManifestResource().

    See these links for more info:

    http://www.attilan.com/2006/08/accessing-embedded-resources-using.html

    http://blogs.msdn.com/b/alexdan/archive/2007/12/19/loading-embedded-resources-in-c-using-getmanifestresourcestream.aspx

    0 讨论(0)
提交回复
热议问题