开发者

HUGE problems using CodeDom compiler, can't use namespaces in the dynamic code

开发者 https://www.devze.com 2023-02-16 21:43 出处:网络
I\'m trying to create dynamically generated code based on user input (just like a mini-compiler). But my problem is that i need to use the PresentationFramework.dll assembly inside the dynamic code, a

I'm trying to create dynamically generated code based on user input (just like a mini-compiler). But my problem is that i need to use the PresentationFramework.dll assembly inside the dynamic code, and i don't know how to reference it.

I have already tried Assembly.Load() and Assembly.Loadfrom(). But all i get is an error saying:

"Assembly not found"

I am used to doing this with the IDE (right click references and then add), but now i need to find some way to do this through code.

I need the assembly to use System.Windows.Shell to create custom jumplists.

This isn't just happening for this specific assembly, but for several others too. But this is the most important one, so if someone could help me with this i would be thankful.

So the baseline is: I need to use the namespace System.Windows.Shell. I need to reference this namespace fully th开发者_Go百科rough code (no IDE). How can this be done? And is it even possible?

I'm using Visual Studio 2010 Ultimate (C#).

Thanks in advance!


It depends on the version of PresentationFramework you want when you need to add it as a reference. Basically, you will find it in :

\Program File\Reference Assemblies\Microsoft\Framework

(for 64-bit compilation, or 32-bit on a 32-bit OS)

or

\Program File (x86)\Reference Assemblies\Microsoft\Framework

(for 32-bit compilation or 32-bit on a 64-bit OS)

These are only the root folders. From here, you can go for example in "v3.0" or ".NETFramework\v4.0" for example.

So you just need to add a reference to a full "[path]\PresentationFramework.dll" instead of just "PresentationFramework.dll", for example:

"C:\Program File\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\PresentationFramework.dll".


Here is the answer straight from MSDN:

If your project references any assemblies, you must specify the assembly names as items in a StringCollection as the ReferencedAssemblies property of the CompilerParameters you use when invoking compilation.

0

精彩评论

暂无评论...
验证码 换一张
取 消