CodeDOM & .Net Modules - code-generation

How do I programmatically embed a .Net module to the assembly generated by CodeDOM?

on VB
dim param as CompilerParameteres
param.EmbeddedResources.Add("dynamiclinklibrary")

Related

access .NET framework tools from powershell

How to access several .NET framework tools from powershell? The tools are listed in the following link :
https://learn.microsoft.com/en-us/dotnet/framework/tools/.
I got to found out that the tools are located under the following path :
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools
How to initiate the script so that we can do the following:
Identify if .NET framework tools are installed or not.
2.Install it if not installed and extract the installed path .
Go to the path and use of the tools for further use.
Today the powershell script is formulated in a way that requires users interaction to point to one of the .NET framework tools, for example CorFlags.exe. The idea is to remove this interaction and locate the file by powershell script if .NET framework tools are already installed or install it first and then locate it.
$CorFlagsExe = (Find-FileDialog -Title "Select CorFlags.exe." -InitialDirectory "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools" -ExtensionFilter "CorFlags.exe")
foreach($f in $Files)
{
& $CorFlagsExe $f.FullName /32BITREQ- /nologo
}
The basic approach is pretty straight-forward
Load desired dll. Using an itext dll for this example. In your case, you need to determine which netfx dll has the netfx class you need to do what it is you want to do
[Reflection.Assembly]::LoadFile(:C:\foo\itext.kernel.dll") | out-null
Example: Instantiate an itext PdfWriter object. The ctor requires a fully qualified pdf file name. In your case, once you know which netfx class you need, you need to find the class docs and determine which ctor you need for the object you want to instantiate
[itext.kernel.pdf.PdfWriter]$pdfWriter = New-Object itext.kernel.pdf.PdfWriter("fully qualified pdf file name")
Example of involving an object method. In your case, study the class docs to learn which methods and and properties you need to use to do what it is you want to do
$pdfWriter.close()
This is a trivial example but it should get you going.
This is what the Add-Type cmldet is for.
Add-Type was added in PowerShell 2.0, so prior to that, the Assembly::Load method was the only way to add assemblies to your namespace. Since PowerShell 3x and beyond, it's improved.
Add a .NET Framework type to a PowerShell session. If a .NET Framework
class is added to your PowerShell session with Add-Type, those objects
may then be instantiated (with New-Object ), just like any .NET
Framework object.
Add-Type -AssemblyName accessib* -PassThru
As for whether you use Add-Type of what 'Nova Sys Eng' has highlighted, there is a good article below on that topic.
Add-Type vs. [reflection.assembly] in PowerShell
There's also an undocumented "using assembly" command (although in ps 6 and above you have to special the path to the dll because there's no more GAC).
using assembly System.Windows.Forms
using namespace System.Windows.Forms
[messagebox]::show('hello world')

The type or namespace name `Xml' does not exist in the namespace `System.Security.Cryptography'

I have to read a signed xml with a
Using System.Security;
System.Security.Cryptography.Xml.SignedXml signedXml = new System.Security.Cryptography.Xml.SignedXml(lic);
First Unity/VS complained that
VS > Error 11 The type or namespace name Xml' does not exist in
the namespaceSystem.Security.Cryptography'. Are you missing an
assembly reference?
So I added a reference to System.Security in Visual Studio (C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Security.dll)...but Unity keeps complaining that
error CS0234: The type or namespace name Xml' does not exist in the
namespaceSystem.Security.Cryptography'. Are you missing an assembly
reference?
I then tried to directly copy the 'System.Security.dll' inside the asset folder...but still the same message!
What am I doing wrong please? What has to be done?
Thanks very much!
Most of the System.Security.Cryptography namespace is excluded from the unity's default .Net 2.0 Subset API. Most probably .Xml is also stripped. So do one of the following:
in Unity click on Ctrl/Cmd + Shift + B to open the build menu, click on player settings. In inspector find API Compatability Level which is set to .Net 2.0 Subset by default. Change it to .Net 2.0 which includes the rest of the previously stripped classes/namespaces.
if the error persists then make sure that the .dll you are copying into Unity is from .net 2.0 framework. Unity can't import libraries targeting framework higher than .net 2.0
This is what is excluded from the unity's Subset API:
https://docs.unity3d.com/412/Documentation/ScriptReference/MonoCompatibility.html
Sorry, I couldn't find the current version of this document
EDIT:
as #user2737085 suggested - you'd also have to add mcs.rsp file to your Assets folder. mcs.rsp should be a text file containing the following line:
-r:System.Security.dll

Powershell import external DLL [duplicate]

I created a dll in C# and would like to use it in PowerShell.
I know I can load the dll using:
[Reflection.Assembly]::LoadFile("MyDll.dll")
But I don't want to use reflection.
Is there a simple way to do include my dll without reflection? Something like add reference to this dll?
In PowerShell 2.0 the cmdlet Add-Type is designed for this, for example:
Add-Type -Path "$env:Xyz\bin\Npgsql.dll"
(it’s more likely that under the covers it calls the same LoadFile but this way is more PowerShell-ish)

Determine difference between COM and .NET DLLs in Powershell

I'm writing a script to copy and move DLLs from the bin folder to a mapped drive, and I need to register/unregister the DLLs during the process. I've figured out how to do all of this, but there's a catch. The program I'm working on utilizes VB6 COM DLLs and VB.NET .NET DLLs. I understand that COM DLLs use regsvr32.exe, and .NET DLLs use regasm.exe, but I am interested in programmatically calling the correct function, based upon the DLL I am moving. Is there a way to determine what time I am using in Powershell?
Call
[Reflection.Assembly]::LoadFile( `mydll.dll`)
It should raise a BadImageFormatException if it is not a .Net dll.
As per MSDN:
"This exception is thrown when the file format of a dynamic link library (.dll file) or an executable (.exe file) does not conform to the format that is expected by the common language runtime. In particular, the exception is thrown under the following conditions:
...
An attempt is made to load an unmanaged dynamic link library or executable (such as a Windows system DLL) as if it were a .NET Framework assembly. The following example illustrates this by using the Assembly.LoadFile method to load Kernel32.dll."

Entity model assembly build on command line

Is there an alternate way of building an entity framework assembly (i.e. with csdl, storage and mapping resouces) at the command line (i.e. csc etc) without the use of msbuild. Our build process and environment is a bit out of date.
Using msbuild instead...
I'm not 100% sure but If you do need to use csc you can use the /resource switch to embed files in the output assembly.