question

AksharaThangam-8316 avatar image
0 Votes"
AksharaThangam-8316 asked TimonYang-MSFT commented

Get caller assembly details from License Compiler

I'm working on a licensing prototype where a piece of information needs to be embedded into the dll during the build time. Below is the approach I have taken to solve this problem

I have two projects, one is a custom project (Project A), where the license information will be embedded and the other one (Project B), responsible for embedding the license information into Project A

Project A has a .licx file embedded into it and this file points to Project B. So, when Project A is built, Project B will be triggered by License Compiler and the license information will be embedded using the SetSavedLicenseKey() method (given below). The below GetLicense() method is called when Project B is triggered by the License Compiler.

 public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
 {
      string text = "Sample Text";
      context.SetSavedLicenseKey(type, Encrypt(text));
      return new License();
 }

Here, I have an additional requirement where I need some information of project A into the GetLicense() method. I tried using the GetCallingAssembly() and other related methods, but they were able to back-track until License Compiler. I would need the information on who is calling the License Compiler. Is it possible to obtain the information regarding the caller of the License Compiler?

dotnet-csharp
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@AksharaThangam-8316
There is an Attribute in C# that can get the method or attribute name of the method caller. Will it help the current problem?
CallerMemberNameAttribute Class

0 Votes 0 ·

@TimonYang-MSFT The CallerMemberNameAttribute Class would help during run time. But my requirement is to get the method caller during build time. During build, the GetLicense() method will be called, during when I would need details about the caller.

0 Votes 0 ·

@AksharaThangam-8316
I tried to find something like this, but unfortunately, I couldn't find it.
Whether it is CallerMemberNameAttribute or reflection, it needs to work during runtime.

0 Votes 0 ·
Show more comments

0 Answers