How can I include transformed dll to an Azure deployment - azure

For my Worker role I run a custom task to modify the dll. However, when I use VS to publish the project to Azure the original binary is deployed and not the modified dll. Why is this happening? How to include the modified binary in the package from within VS
This is with sdk+tools v1.6

A possible workaround that I see, is to extract all the code/logic that requires assmebly modification in a separate class library project. Do the custom post-build modification on the class library.
In your worker add reference to that class library. If it also does not work when you add the reference as a project reference, then just copy the resulted modified assembly in a common external references folder for the solution, and add the reference from there (just browse to the final assembly).
I don't know the nature of your modification, but I think that if you cave all your "private" code in a separate class library it will be enough. As the worker implementation will just be calling a "Run()" or similar method of your class library, inside the Run() method of the RoleEntryPoint.

Related

References within an azure functions project not working

So I have some Azure Functions I need to publish, which I want to do via a functions project. However, those functions rely on references to class libraries within my solution, and the references do not work within a functions project, is there a way around this?
Edit: After adding the references to the other projects, when "using" the namespaces in which the classes are kept, the compiler throws an error "cannot resolve symbol", it is as if the reference does not exist. The functions project will not build because it cannot find the namespace in which the classes exist
Verify that each project targets the same version of .NET framework. I had the same problem until I noticed that the referenced project targeted 4.7.1, but my Azure function project targeted 4.6.1. Changing the referenced project to match the Azure function project resolved the issue.
There are a couple more steps to consume assemblies if they're not exposed by default in Azure Functions. If it's a custom assembly you have to make sure it's included in the bin folder. Then you have to make sure you're using the #r directive. Are you doing both of those things? Include your code header and settings if so.
This page has the list of assemblies that are visible to Azure Functions, some still requiring the #r directive:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#referencing-external-assemblies
The following assemblies are automatically added by the Azure Functions hosting environment:
mscorlib
System
System.Core
System.Xml
System.Net.Http
Microsoft.Azure.WebJobs
Microsoft.Azure.WebJobs.Host
Microsoft.Azure.WebJobs.Extensions
System.Web.Http
System.Net.Http.Formatting
The following assemblies may be referenced by simple-name (for
example, #r "AssemblyName"): Newtonsoft.Json
Microsoft.WindowsAzure.Storage Microsoft.ServiceBus
Microsoft.AspNet.WebHooks.Receivers Microsoft.AspNet.WebHooks.Common
Microsoft.Azure.NotificationHubs

How to create a class inside Microsoft Azure Function?

May be it's a wrong question, but I need to create a Model/class and access same in azure function. I could not able to find how can I create a class.
Classes may be created inline as it would typically define a class in a regular C# project. Here's an example of a function that defines a class.
You can also define classes in separate files and reference those files using the #load directive as documented here.
Another option is to reference an assembly where your classes are defined, as documented here.
And, a different approach, and yet another option, is to use the newly announced Visual Studio 2017 Tools for Azure Functions

MVC Ninject: How to add NinJect bindings from an MVC Area project

I've been using this blog example:
http://blog.longle.net/2012/03/29/building-a-composite-mvc3-application-with-pluggable-areas/
I have the concepts working in my solution. However, I'm trying to figure out a good way only add bindings to the kernel if a user has permissions to access a module/area.
I've read up some on the ServiceLocator but I was trying to stay away from it.
One thing I'm trying just to get things to work is user Contructor injection in the default constructor for a module. It's working but is a hack.
The pattern I'm using, each module project you create an class that inherits from AreaRegistion. When each module project builds, relevant files are copied to the Areas folder of the main web project. Then when the main project loads, reflection is used to load all module assemblies. Then when AreaRegistration.RegisterAllAreas() is called, it detects and loads all the modules with a class that inherits AreaRegistration.
I'd like to figure out an good way to access the Ninject kernel and add bindings in the module class that inherits from AreaRegistration. I would imagine initiating code to add bindings from the RegisterArea() override.
I'm looking for any suggestions on how to do this without resorting to the ServiceLocator.
Any ideas would be greatly appreciated.
For now I've found a better solution and that's to use NinjectModule. In the Plugin class, I'm going to create a class which inherits from NinjectModule. Then setup the pluging bindings in the Load overload.
Then use Kernel.Load in my main app bootstrapper to initialize the Load overloads in all plugin classes which inherit from NinjectModule.

Win8 app CLI library integration issue

I have a Win8 app that is purely native (c++) and I've already used a library that is written using managed code AFAIK. No issues there, I created objects and addressed them using C++/CX with ref counted pointers etc.
I need to add a new library, I referenced it as I did previously, but when I declare and object and try to address it I get:
error C3624: 'System::Object': use of this type requires a reference to assembly 'mscorlib'
Using #using <mscorlib.dll> is not a solution obviously, because WinRT does not support #using of a managed assembly.
When I look up the definition of the class I'm using in Object Browser I see that it's inherited from System::Object. The previous library had a class that was inherited from Platform::Object which is valid for C++/CX.
I already contacted the developers of current library I'm trying to use, but it takes a lot of time for them to respond.
Can I work around this issue? What are the possible courses of action?
UPD: Can I ask the developers to rebuild a library for C++/CX?
I do not believe this is going to work in the general case, unless the C# library is a PCL (portable class library). If it leverages anything that is not in the WinRT .NET client profile, it simply will not work.
If it is a PCL, what you can do is write a C# Windows Runtime Component that itself has a reference to this third-party library and wraps the necessary functionality. Then you reference that C# Windows Runtime Component from your C++/Cx application.

Robolectric uses incorrect resource id from library when inflating view

This is not exactly a question as I found the solution for the problem. Just hope it will help others who can encounter it.
We use Robolectric to write unit tests for a project which uses a library (actually several libraries). The libraries as well as application uses a lot of resources.
Lets suppose that Eclipse workspace contain project Library (with "library.package" as top package) which creates an Android library and project Application (with "app.package" at the top) which uses Library. the project Test is Robolectric project which refers to the Application project.
All of a sudden we found that very simple test which checks for existence of a particular view in the activity fails. For example:
#Test
public void testProgressBarInit() {
LoginActivity activity = Robolectric.buildActivity(LoginActivity.class).create().get();
assertTrue(activity.findViewById(R.id.status_text) instanceof TextView);
}
The library project implements the LoginActivity and defines an appropriate resources (layout). Failing tests run perfectly before we changed our code structure a little bit eliminating one more library.
Running the test under debugger showed that findViewById call uses correct value of the R.id.status_text taken from Application/gen/R.java file. At the same time, we discovered that the value of R.id.status text in the Application/gen/R.java differs from the value in Library/gen/R.java. Also, the Appication/gen directory contains file library.package.R.java which contains the same value for status_text as in the Application/gen/R.java (which differs from original one in the Library/gen/R.java). It is normal behavior of aapt tool which can change resource ids while merging resources from the library and the application.
After some investigations we found the following:
Robolectric loads resource IDs which was defined in the library twice: once using R.class from application project and another using R.class from the Library project
which class is loaded depends on the class path configuration
to run tests we need to export the Library project from the Application project
if Library project is exported before Application/gen folder in the class path configuration, Robolectric replaces resource ids by those found in the Library/bin/classes/library/package/R.class
if Library project is exported after Application/gen folder, Robolectric uses correct resources found in the Application/bin/library/package/R.class.
It is certainly a bug in the Robolectric implementation as it should not load resource ids from R.class associated with library package. All ids are propagated to the Application/gen/R.java (see discussion here on GitHub).
If you encounter this or similar problem with resource usage while using Robolectric, make sure that you export library project after Application/gen folder in the Build Path-Order and Export configuration.

Resources