Reference c# class library in my Azure Function - c#

Is it possible to reference a c# class library in an Azure Function visual studio project?
I am aware of the possibilities to reference external libraries and Nuget packages.
Currently I am using shared .csx files as described here. These .csx files now contain a copy of my DTO's which are also used in the Service Agents which I use to consume the functions.
Ideally I want to add a reference in Visual Studio from a Function to a class library project and that Visual Studio is adding this dll to the bin folder.

Currently, project references are not supported, but you can have the output of your project (the resulting assembly and possible dependencies) copied onto a folder under your function's root, which you can then leverage using the external libraries support you've mentioned above (e.g. #r "..\myassemblyfolder\MyAssembly.dll")
If possible, I'd suggest opening an issue with that feature request, sharing more about your scenario on this repository. This allows other people to upvote those requests and helps the team prioritize this work.

Previously this was not possible. This is now possible as you can read here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-class-library.
Old answer:
This is now possible by using the new Visual Studio 2017 Tools for Azure Functions.
You can get more information about this in the following links:
Visual Studio 2017 Tools for Azure Functions
Azure Functions Visual Studio Tooling video

Related

How to add a c# project as a resource in a class library c# project?

I have been working on a class library that generates c# projects from an existing c# project. Right now I have the template project in a specific folder on my machine but what I really need is to add that template project to the class library as a resource, so I could distribute the dll. Any suggestion will be very helpful.
If I'm understanding this correctly, and you're saying you've got a project that produces new C# projects (so .csproj and .cs files) and you want to add those as a resource, then I'd zip them up and add the zip as a resource.
Also have a look at the way new templates in Visual Studio are distributed. Within Visual Studios program files you'll find the built-in templates for example "C# Console Application" and "VB.NET WinForms" in the default path "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ProjectTemplates", however you can always download new ones from online and add them to Visual Studio, I'm guessing they could be zip or some form of packaged file.
There's information from Microsoft on how to create your own project templates and mentions about zipping them up https://learn.microsoft.com/en-us/visualstudio/ide/how-to-create-project-templates?view=vs-2017
There's also a guide here on how to create your own project templates https://www.ecanarys.com/Blogs/ArticleID/180/Create-custom-project-templates-in-Visual-Studio
Having a look around at distributed project templates, they mostly come from the Visual Studio Marketplace.
Video 18 of this series on the Microsoft Virtual Academy might help you.
Creating and Adding References to Assemblies
https://mva.microsoft.com/en-US/training-courses/c-fundamentals-for-absolute-beginners-16169?l=Ry6jz0QIC_5706218949

Import Azure Function from portal into Visual Studio

I really like working with Azure functions in the portal but am starting to need some more tooling that I'm used to for committing to my git repo, easily adding assemblies, and just plain working in a more familiar environment.
Is it possible to create your Azure function app and possibly the functions themselves in the portal and then move over to Visual Studio and import that function app as a project? Or am I approaching this wrong? I understand we can create straight from Visual Studio and then publish up to Azure and maybe that is the way we should be doing it in the first place.
A few pieces you could do. You can start development in the portal and then download the app settings (connection strings, etc.) via the azure-function-core-tools with a CLI command like func azure functionapp fetch-app-settings <appName> - but that will just pull the settings into an existing local project.
You could also go to the Platform Settings tab and open the App Service Editor which would let you download the workspace as pictured below. That will download the function project into a folder you could check into source control and use with CI/CD.
However one important note is the portal for C# projects use C# script files (.csx), and the Visual Studio tools for Functions create .NET assemblies (.dll), so if using C# you wouldn't be able to download the workspace and open it up in Visual Studio - you'd likely be better off just copy/pasting the code into a Visual Studio project.
Personally since the latest v3 update of VS 2017 I find starting in Visual Studio is even more convenient than the portal was for Function apps.

Using .Shared project in windows 8 app

I have an universal app, which contains shared project between Win8\Phone project. And i have some winRT component(project for background task), so how i can link from background task's project to shared project in universal app?
The Shared Project Reference Manager extension will enable this functionality for Visual Studio 2013. Once that extension is installed, you can browse and add shared projects as you would add any other reference to a project.
There are two caveats to be mindful of:
The extension adds an entry into your project file (.csproj). That entry has a condition on it that only adds it if the shared project file path exists. While perhaps seeming innocuous, this can lead to a bunch of orphaned entries in your project file if you rename, move, refactor things, or, if there is an issue with the shared project on disk such as changing its location, you only find out about it at compile time, not when the project is loaded.
As noted in comments for the extension, the extension causes performance issues with Visual Studio 2013 when you have a large number of projects, especially during startup/shutdown of Visual Studio.
Visual Studio 2015 has built-in support for shared projects, and provides a much richer set of functionality baked into the IDE:
http://www.c-sharpcorner.com/UploadFile/7ca517/shared-project-an-impressive-features-of-visual-studio-201/

How do I use RedditSharp in Visual Studio (2012)?

I am making a C# Web Form application and I want to use RedditSharp. https://github.com/SirCmpwn/RedditSharp
I've never used an API in C#, this would be my first time using something outside of the C# generics. Could someone help me understand how to import it to use it?
Create C# Web Forms project in Visual Studio
Download RedditSharp code from Github
Compile RedditSharp into DLL (build enclosed solution, grab DLL from the bin/release folder or wherever it builds to)
Add a reference from your project to RedditSharp DLL
Check examples at https://github.com/SirCmpwn/RedditSharp, add something like that to your code
Don't forget to add "using RedditSharp;" to the top of your code file.
Easiest thing to do in Visual Studio is to install the nuget package. Go to Tools...Nuget Package manager... Manage Packages for Solution. Search for RedditSharp, click install.
Now you can reference it from anywhere in your project by adding:
using RedditSharp;
This has the added benefit of Visual Studio alerting you to new updates anytime the official RedditSharp project is updated.

How to use open source library in C#?

I would like to use log4j.net in my windows forms project. However I have never used any library or dll in .NET. How to do it? I look at the site, but I can't find it.
I'm using visual studio 2010.
Add the log4net assembly to your project:
Browse to the log4net downloads page and download the latest log4net archive
(right now the latest version is 1.2.10).
Extract that archive and place the files somewhere to your project
(for example in a folder like yourproject/lib/log4net).
In Visual Studio right click in your project on the References folder and click on Add Reference....
Browse to the folder where your assemblies are (see point 3) and choose the log4net.dll assembly.
Here are some nice basic tutorial for the first steps using Log4Net:
Log4Net Tutorial pt 1: Getting Started
Using Log4Net in 4 Simple Steps
Log error or exception using Log4Net
In your project, you need add a reference to the library, usually by selecting the DLL from the references dialog.
A package manager, NuGet, has been created as an add on to Visual Studio 2010, which lets you select libraries - it will download and set them up for you.
Whichever way you do this, you will now be able to use the library - in a code file, use the using directive to import the namespace, then you can use the classes and other public members of the library in your code (though you could use the fully qualified name every time, if you wish to).
This has nothing to do with a library being open source or not, by the way.
you can easily get now using NuGet package manager in visual studio 2010
Write this command in Package manager console.
Install-Package log4net
See this link
Do you have any specific problems?
Check link below and maybe ask a question if you are stuck on something:
http://sadi02.wordpress.com/2008/06/29/log4net-tutorial-in-c-net-how-can-i-show-log-in-a-file/

Categories

Resources