I'm using ICSharpCode.SharpDevelop libraries for my project. I'm trying to figure out how to construct an instance of DefaultProject so that it has all necessary references. So, I need something like

 projectContent.AddReferencedContent(_projectContentRegistry.GetProjectContentForReference("System.Core", "System.Core"));

Except that it doesn't work -- GetProjectContentForReference(..) always returns null, whatever I'm trying to provide for the arguments.

有帮助吗?

解决方案

It looks like a bug in the ProjectContentRegistry class in SharpDevelop 4.x. If you debug the GetProjectContentForReference() method then you can see it is looking in the wrong GAC folder. It is looking in the folder

System.Core\4.0.0.0__b77a5c561934e089\System.Core.dll

when it should be looking in the folder

System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll

I suspect this bug has not been noticed since SharpDevelop now uses MSBuild to work out the location of assembly references. With System.Core for example it will find the assembly in the reference assemblies folder based on the project's target framework:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Core.dll

What you can do instead is find the filename using the GacInterop class that is part of the ICSharpCode.SharpDevelop.Dom assembly. The code below should return a non-null project content object.

var reference = new DomAssemblyName("System.Core");
reference = GacInterop.FindBestMatchingAssemblyName(reference);
string fileName = GacInterop.FindAssemblyInNetGac(reference);
var registry = new ProjectContentRegistry();
IProjectContent pc = registry.GetProjectContentForReference("System.Core", fileName);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top