5

I am trying to reference a class library from a Visual C# SQL CLR Database Project but I get the error

A reference to 'class library' could not be added. SQL Server projects can reference only other SQL Server projects.

Is there a way to add the reference so I don't need to duplicate the code in that class library?

EDIT - Solution?

My current solution, is just adding the few required class files to the SQL CLR Database Project as links to the real files. That way code is in one place, even though it will build in two different spots. It seems to work for my purposes.

1 Answer 1

6

This restriction exists because the referenced assembly must be registered on the server first. Execute the CREATE ASSEMBLY sql statement, I used this one to test it:

CREATE ASSEMBLY ClassLibrary5
FROM 'c:\projects\classlibrary5\bin\release\classlibrary5.dll' 

Next, use Add Reference on your database project, the registered assembly shows up in SQL Server tab.

Sign up to request clarification or add additional context in comments.

6 Comments

@Hans Passant, there's no way to have VS do this automatically when adding a reference to a regular class library?
Well, sure, you can add a reference to another SQL Server project in your solution. I got the distinct impression that you wanted to reference a regular class library, isn't that what your question asked?
That's exactly what I want, a regular class library. But, I was hoping I wouldn't have to register it every time I make a change to it. It would have been nice if VS would let me add the reference to the SQL Server project and handle the registering of the regular class I referenced when I select deploy on the SQL Server project.
The best place for feature requests is at connect.microsoft.com There probably is already one there, vote it up to get them to pay attention.
Is there a way through pre-post build scripts I can get this to happen?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.