This should be the counterpart to "RegisterAssembly".
I need it for our implementation of the SnippetParser sample, because the users have the ability to add and remove additional references by entering the assembly name in a text field.
I created the method myself, but I think you could add it to your API.
Here is my implementation:
public void UnregisterAssembly(string _strAssembly)
{
//Similar code to "Alternet.Syntax.Parsers.Roslyn.CodeCompletion.RoslynSolution.RegisterAssembly"
RoslynSolution rosSol = this.vbMethodParser.RoslynSolution;
string strAssemblyPathAndName = rosSol.ResolveAssemblyName(_strAssembly);
//Empty path means "wrong Assembly" (e.g. framework DLL)
if (string.IsNullOrEmpty(strAssemblyPathAndName))
return;
//For removing the MetadataReference we have to use the existing object. Removing a newly created MetaDataReference does not do anything.
//Case insensitiv comparison.
Project project = rosSol.Solution.GetProject(rosSol.ProjectId);
MetadataReference metaRef = project.MetadataReferences.FirstOrDefault(meta => meta.Display.ToLower() == strAssemblyPathAndName.ToLower());
//If not found then abort
if (metaRef == null)
{
return;
}
//See code of "RoslynSolution.RegisterAssembly" and the method "ApplySolutionChanges":
Solution solNew = rosSol.Solution.RemoveMetadataReference(rosSol.ProjectId, metaRef);
rosSol.Workspace.TryApplyChanges(solNew);
rosSol.Update();
}
Thanks
Wolfgang Knauf
Hi Wolfgang,
Thank you for the suggestion, we will include this method in the next public release.
regards,
Andrew
Thank you for the suggestion, we will include this method in the next public release.
regards,
Andrew
Thanks!
Wolfgang
Wolfgang