Saturday, 11 March 2017

Accessing a "Class Library (.NET Standard)" from a "Console App (.NET Framework)"

If you're trying to access a class library (.NET Standard) from a traditional console application (in VS2017 those can be found under 'Windows Classic Desktop') you will run into problems; which can feel a little strange for something that was pretty simple in VS2015 and earlier. You can add a reference to the class library project (Resharper will even volunteer to add the dependency / namespace reference if you don't already have it). But the code won't then compile, it will complain that it can't find the namespace referenced in the using and it also won't be able to find any of the objects that you reference in the class library. Took me a bit of figuring out but you need to open up the properties for the class library project, look at the conditional compilation symbols in the build tab (it might be something like 'NETSTANDARD1_4'). You need to take this symbol and duplicate it in the build tab of the console application. You should now be able to rebuild your solution and if you have other code errors, etc the solution should now build.

No comments:

Post a Comment