Search code examples
c#.netsql-serverportable-class-librarydatabase-project

Issue referencing a portable class library from a SQL Server database project


I created a test solution in that includes three projects. There's a database project, a PCL and a standard class library (let's call it SCL). They're all C# projects targetting .

If I add a reference from the database project to SCL, everything compiles without issues. If I also add a reference from database project to PCL, again everything compiles without any warnings in the build output.

However... there's this:

enter image description here

I noticed that little warning sign on the PCL. Unfortunately that's all I have. There's no build issues, no clues in the build output, no tooltip if I hover the sign... nothing. I couldn't find anything on the net about using (or not using) PCL as references for apps either.

Anyone has an idea? Is there any problem with referencing a PCL from a SQL Server database project in Visual Studio? Why is it treated differently than SCL?

I can't do much test because right now I do not have a DB yet. I'm just planning ahead.


Solution

  • For others who find this question and wonder at the icon (as I did), this yellow symbol appears when the type library is built against a different .NET framework version:

    enter image description here

    This is usually the case with database projects using newer class library builds as Visual Studio 2013 creates .NET 4.0 projects by default*.

    To remove the symbol, ensure your database project and class library use the same .NET Framework version, (e.g. 4.0, 4.5.1, etc.).

    enter image description here

    You can set the target framework of your database project via Properties->SQLCLR->Target Framework:

    enter image description here

    As far as I can tell it is just a warning flag, as code compiles, links and runs as expected.

    kad81's response


    * - .NET 4.5 when using 'New Project' from the database context menu of the SQL Server Object Explorer. Using SQL Express 2014 SP1