locked
Build Action for ResourceDictionary in Portable Class Library

    Question

  • I have a Portable Class Library with a XAML file containing a ResourceDictionary. Visual Studio 2013 let me add the ResourceDictionary perfectly fine, but when I try to compile it, I get an error about the Build Action. In Windows Store apps, the Build Action would be Page, and in Windows Phone apps it would be Resource. Page (which is what Visual Studio 2013 set it to when I added it) gives an error (which makes since, since Page is not supported for Windows Phone), and Resource is not listed as an option for Build Action in the PCL. My best guess would be Embedded Resource. Is this what it should be? If not, which one should it be? I am still learning the restrictions and how to make full use of Portable Class Libraries (I am working on converting my apps to Universal Apps). Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Wednesday, July 16, 2014 5:44 PM

Answers

  • That is not needed! Refer below screenshot for how it will look like.

    This new Shared Project type actually does not get compiled on its own, Visual Studio automatically compiles it with other projects (Win 8.1 & Win Phone 8.1) where it is referenced. This is something like file linking where you can have only one physical copy of file but it is linked to various projects; in here this shared project itself gets linked.

    For file linking (which is not needed as of now) in a project you say add existing item and there select 'Add as Link" in the dropdown shown here


    -- Vishal Kaushik --

    Please 'Mark as Answer' if my post answers your question and 'Vote as Helpful' if it helps you. Happy Coding!!!


    Thursday, July 17, 2014 3:23 AM

All replies

  • All your XAML related stuff should reside in Shared project.

    And then you can use that dictionary in App.XAML file like this

    <Application
        x:Class="MsdnSample15072014.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:MsdnSample15072014">
        <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="Dictionary.xaml"/>
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Application.Resources>
    </Application>

    PCL is not meant to share code that needs to be compiled differently for platform.


    -- Vishal Kaushik --

    Please 'Mark as Answer' if my post answers your question and 'Vote as Helpful' if it helps you. Happy Coding!!!

    Wednesday, July 16, 2014 6:03 PM
  • So even though I have multiple Styles that are exactly the same (every property) for both Windows and Windows Phone I still need to make two copies and put them in the projects separately? Is there any other way to share Styles between Windows and Windows Phone? I would have thought that for Universal Apps there would be some way to share Styles so that if the look of the apps changed (for example, the theme colors for text and buttons) you could keep the apps looking the same by always sharing the Styles. No workarounds or alternatives? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Wednesday, July 16, 2014 7:27 PM
  • If you put something in Shared Project it is just one copy! I am not sure why do you say two copies of same thing?

    -- Vishal Kaushik --

    Please 'Mark as Answer' if my post answers your question and 'Vote as Helpful' if it helps you. Happy Coding!!!

    Thursday, July 17, 2014 1:53 AM
  • I say two copies because I need to know what Build Action to use in the shared project. If I do not know what Build Action to use, I will need to put a copy in the Windows Phone project and a copy in the Windows Store project separately, which would make it two copies.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Thursday, July 17, 2014 2:35 AM
  • That is not needed! Refer below screenshot for how it will look like.

    This new Shared Project type actually does not get compiled on its own, Visual Studio automatically compiles it with other projects (Win 8.1 & Win Phone 8.1) where it is referenced. This is something like file linking where you can have only one physical copy of file but it is linked to various projects; in here this shared project itself gets linked.

    For file linking (which is not needed as of now) in a project you say add existing item and there select 'Add as Link" in the dropdown shown here


    -- Vishal Kaushik --

    Please 'Mark as Answer' if my post answers your question and 'Vote as Helpful' if it helps you. Happy Coding!!!


    Thursday, July 17, 2014 3:23 AM