Retrieve Source Code Files from Azure Function in Azure Portal - azure

I had developed azure function solution in Visual Studio 2019 and deployed to azure function by downloading publisher .
But accidently I had deleted entire source code in local machine where I could not get even from "recovery software tools" also.
is there any way can I get source code files from azure function development tools in azure portal? or local machine C drive?

If you open up the Azure Function App Service and navigate to the "Functions" section you will be able to open your individual functions and then select the "Code + Test" section and be able to see your function
I don't know if the type of Function you developed impacts your ability to see this source code or not.

When you deployed through Visual Studio, the source was compiled locally and only the DLLs were uploaded. Thus, you cannot directly see your code. However, you can get to your DLLs and download those. Then you should be able to use any decompiler to see your source code again (maybe not as pretty as originally...).
Go to the SCM console to see and download all files: https://{YOURFUNCTIONNAME}.scm.azurewebsites.net/dev/wwwroot/

Related

How can I debug on Azure Devops VSO

I have made a task for Azure Devops Server pipeline.
On the local Azure Dev-Ops server, I can upload extensions from the local machine wrapped in VSIX file and examine the agent on the machine itself. The agent has the deployed DLL's from the extension and I always change specific DLL that has Logger inside and it prints to console on the pipeline itself.
How can I check if my task is compatible with the cloud version?
And off course if it is, how can I debug it?
The only possible way I found to insert my task in VSO is through the Microsoft DevOps marketplace, but I cannot upload the whole extension once per each change in code.
Also, didn't find a way to upload personal tasks to the marketplace. The private version is not helping because I can see it from within the server just like my clients.
Any advice or debug experience on that platform is appreciated.
Please follow this devblogs, it described how you can work and debug extension directly inside your IDE without publishing it to the marketplace.
Since this blog is very detailed, just mention the key steps.
Based on debugging purposes, you need create a special manifest, for sample I specify it as vss-extension-debug.json:
{
...
"id": "dev-extension",
"name": "Dev-Extension",
"baseUri": "https://localhost:44362",
...
}
You can customized the id and name by yourself. The most important and magic is baseUri, this will tell the VSTS server to load the extension from localhost where we can run and debug it in IISExpress from Visual Studio.
Note: Since our server need extension served from a secure source, please ensure enable SSL mode to run IISExpress

What is the best way to move an online Azure Function to a local git repository?

I have written an Azure Function App by using the User Interface of Azure Portal. The code is written in C#.
Now, I want to:
download all of the relevant code and configuration files of this
function app
Create an IDE project (e.g. IntelliJ, Visual Studio Code, ...)
store it in a git repository
Deploy the code from IDE or command line to Azure and thereby replacing the previously written Azure function.
So far, I have found only documentation on how to initiate Azure function projects with no previous code. Does somebody know how to do above?
Yes, you could go to your function Overview page, click on Download app content as shown below.
And in your situation, you want configuration files, so select the Content and Visual Studio Project and Include app settings in the download. What is app settings? This will include a local.settings.json file which contains your application settings.
Also the third party .dlls are included.
In the VS, select the folder and it will be working.
Update:
Open the function with vs, then just right click the function and choose Publish, it will show you the publish page. Click start, then you will be able to publish it to a existing Function.
Follow this Setting up a CI/CD pipeline for Azure Functions doc which explain each step in detail.

How to debug Azure Functions using Visual Code

I have an existing set of functions in an Azure Functions App written in C# Script. I've downloaded the zip file from the Azure portal and opened the directory in Visual Code. I can also log on to the Azure account from Visual Code and can see the functions. If I right-click, I get options to start and stop streaming logs
However, I don't know how to configure my environment so that I can edit and debug these functions locally. I've found instructions for creating a new Function App, but haven't found ones that describe how to work with an existing app.
As mentioned in this post, for now we can't debug(add break points to) C# script(.csx) functions in VS Code.
We can only run csx function both on Azure and locally. Open the function app folder in VS code, follow steps below.
Check function runtime version(~1 or ~2) and follow tutorial to install Azure Function core tools.
If we use ~2 runtime, you need to register binding extensions for all triggers/in/output except Http and Timer triggers.
If we want to use settings(like AzureWebJobsStorage) in Application settings, copy them into local.settings.json. Or we can right click on Application settings of the Function app in VS Code, click Download Remote Settings(In this way, some invalid settings for local env are downloaded as well).
Input Ctrl+` to open terminal and input func host start in terminal to run functions.
For local dev, I do recommend you to use C# pre-compiled code instead of C# script, which is much easier to work with. To do this transformation, follow this tutorial, new a c# function app locally, copy your code in .cs files. We basically don't need to modify the logic code except adding some package and namespace references.

Where can i find the code of an Azure Function?

I'm new to Azure Functions and been thrown into a project without a proper introduction and anybody I could ask is out of office. My simple most likely stupid question is; where can I find the actual code?
In the azure portal, the functions are listed as "read-only" and only contains a function.json. The resource is an App Service and it has a couple of functions. There is no link to any git repository in properties.
Read-only Functions would be compiled and published (e.g. through Visual Studio or a CI/CD pipeline.) The Azure Functions Portal engineers are working on a new, improved experience for this but for now, if your Function app has a deployment source configured, you can view it from the Portal in two ways from your Function app:
Platform Features > Deployment Options.
Platform Features > Resource Explorer. In the file tree on the lefthand side, find your Function app's name, and under that, sourcecontrols. Click to expand in the righthand window.
If your Function app doesn't have a deployment source configured (e.g. your team has been publishing code manually) then things get harder. Depending on how your company has set up their source control and what you already have access to, the function.json you see might help: the entryPoint property in a build-generated function.json will give you the full assembly name of that function (e.g. VSSample.HelloSequence.Run). That or the assembly name of the uploaded DLL in the scriptfile property might help you locate the project.
Good luck! Keep posting if you have further questions; we're here to help.
AFAIK, if we create the azure function in the Visual Studio and publish it to Azure(there may be other ways), it will appear in the situation you described like the screenshot.
Actually, the code is existing in the portal, but the code has been compiled, you could access it in the Platform features -> Advanced tools (Kudu) -> Debug console.
If you want to get the .cs file, I think you should ask it for your coworkers, there will not be in azure.
You said that the Azure function is listed as "read-only". Did you check from the Application Settings menu if you can change the Azure function app edit mode to Read/Write?

How to debug Azure Functions on Azure Portal?

I have created an Azure function. Can i debug Azure Functions on Azure portal without visual studio?
I am passing a complex parameter as File Model, i have to see what's coming in parameter value in debug mode?
There is no debug experience in the portal. Constrained to just the portal, you'll have to use log output to debug.
You might also look into the Azure Functions CLI which provides a local debugging experience. it doesn't require VS.
For Azure Functions V1, you can attach debugger then debug from Visual Studio as the code runs inside csx script:
https://markheath.net/post/remote-debugging-azure-functions
For Azure Functions V2, It seems there is no way till now but you can get massive logs and analytics based on your need.
Or may be you can find a way by uploading the debug version contains (.pdb files) and try to attach debugger. Check this:
https://github.com/Azure/Azure-Functions/issues/872
And i opened an issue here to ask about this:
https://github.com/Azure/Azure-Functions/issues/1051
I have another easiest solution It may feet in your issue or may not, I faced a situation that i want to test azure function webhook but that wouldn't work with localhost so the only solution for me is to test it after publishing and for that i was in need for debug on azure itself but there is another brilliant solution:
You can expose your localhost urls to the public by using many services and for example:
https://localtunnel.github.io/www/
Make sure that you installed nodejs, and follow the instructions to install the localtunel package globally through npm and then you can generate a public url for your localhost webhook so you can verify it against any third party and debug it.
Through Azure Functions Portal you won't able to have debugging tools for do that.
But you can you some ways to debug your azure functions:
1º) Remote debugging using Visual Studio IDE;
2º) Local Debugging using both Visual Studio or VS Code, too;
3º) Event though you're using Azure Functions CLI, you'll need some IDE, that is Visual Studio or VS Code;
The only way that there is on Azure Functions Portal to have something like a debugging is the LOG Window that is localized right below Function Code Window.

Resources