Spark View Engine Missing Libraries visual studio 2010 - c#

I am using the Spark View engine with asp.net mvc3, gotta say I love spark bindings are awesome!
Everything works fine however development is extremely painful at the moment because any time I change
any of my code I get Runtime Binder errors such as
The type or namespace name 'RuntimeBinder' does not exist in the namespace 'Microsoft.CSharp'
I am forced to clean and rebuild my solution and restart it and it works fine after that. Well at least until I make another code change and am then forced to do it again.
Stopping IIS instance and starting project does not work I have to do full rebuild first.
I am running in Debug.
I have Rebooted,Checked Referenced DLL's, Cleared all files out off Tmp,Checked my web.config and spark file.
I have added the following code in my global.asx file as explained here.
Spark views work initially, but then get a "Dynamic view compilation failed" error after 30 minutes or so
private void PreLoadAssemblies()
{
// Deal with the compiling issue with Spark.
var initialAssemblies = AppDomain.CurrentDomain.GetAssemblies();
var di = new DirectoryInfo(Server.MapPath("~/bin"));
var files = di.GetFiles("*.dll");
foreach (var fi in files)
{
var found = false; //already loaded?
foreach (var asm in initialAssemblies)
{
var a = Assembly.ReflectionOnlyLoadFrom(fi.FullName);
if (asm.FullName == a.FullName)
found = true;
}
if (!found)
Assembly.LoadFrom(fi.FullName);
}
}
I guess this is not a crucial bug/problem and may not be worthy of stackoverflow users time as I can work around it but its bugging me more and more each day, and maybe someone has fix.

Related

How to get "Include Paths" property of Microsoft Macro Assembler in Visual Studio by a plugin?

I'm workng to get include path resolved by some VS plugin (asm-dude in fact). Include path in microsoft macro assembler looks like this:
includepath
Include file resolve part in asm-dude lies in: https://github.com/HJLebbink/asm-dude/blob/vxix2022-B/VS/CSHARP/asm-dude-vsix/Tools/LabelGraph.cs#L602
Anyway, at the beginning I think I just need to get the value of IncludePath property, and then other things can be done in a minute. But after reading some docs I realized I'm in a mess. It seems that VS prevents me to get names of all properties, but I can only get the value by the name.
Codes I write are like:
DTE dte = Package.GetGlobalService(typeof(SDTE)) as DTE;
Projects projects = dte.Solution.Projects;
if (projects.Count != 0)
{
VCProject project = (VCProject)projects.Item(1).Object;
VCConfiguration cfg = project.ActiveConfiguration;
if (cfg != null)
{
string includePathStr = cfg.GetEvaluatedPropertyValue("IncludePaths");
}
}
but in vein, it gets include path of msvc, not MASM
I cast Project to VCProject because it's a VC project. Although I can iterate properties of a non-VCProject's configuration, but it doesn't seem to work on VCProject, because it doesn't have a (at least not public) member named properties. All these docs tell me that I can only get its value by name, but the problem is I don't know its name. Or I'm completely wrong? I must admit that I'm new to VS plugins.
refs I used so far:
https://learn.microsoft.com/en-us/previous-versions/dn655034(v=vs.140)?redirectedfrom=MSDN
https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.vcprojectengine.vcconfiguration?view=visualstudiosdk-2022

Getting the StartArguments from a VSIX plugin for .NET Core projects

EDIT - Looks like the initial problem only applies to .NET Core projects. So the question shifts to "What is the correct way to get the full range of project properties from .NET Core projects?"
I'm writing a Visual Studio 2019 plugin that uses some of the project configuration settings. It seems straight forward enough to get the Project object (C# here, but also C++ & others) and then spelunking the Configuration's for Property objects.
But it appears that accessing most of the properties will throw System.NotImplementedException.
Primary Question: Is there another way to access these settings - like startup arguments and other debugging configuration?
Secondary Question: Are there any good resources on this stuff? The online MS docs are a bit terse for my taste.
void ProcessCSharpProject(VSProject csProj)
{
foreach (var config in csProj.Project.ConfigurationManager.Cast<Configuration>())
{
Property debugInfoProp = config.Properties.Item("DebugInfo");
var debugInfo = debugInfoProp.Value as String; // works
Property startArgsProp = config.Properties.Item("StartArguments");
var startArgs = startArgsProp.Value as String; // NotImplemented
// Another way to access the same thing:
var configProps = config.Object as CSharpProjectConfigurationProperties6;
var startArgs2 = configProps.StartArguments; // Also NotImplemented
}
}
Thanks!

Unable to load one or more of the requested types - but not the normal error

Okay, so this is a really bizarre one that has been bugging me. It will be hard to explain so please bear with me!
I am using autofac to register some components by scanning references.
public static void RegisterHandlersKeyedByEnum(this ContainerBuilder builder, Assembly[] assembliesToScan, Type typeToRegister)
{
var handlers = assembliesToScan.SelectMany(a => a.GetTypes()).Where(t => t.GetInterfaces().Contains(typeToRegister));
foreach (var handler in handlers)
{
var handlesAttributes = handler.GetCustomAttributes(typeof(HandlesEnumOf), true).Cast<HandlesEnumOf>();
foreach (var handlesAttribute in handlesAttributes)
{
if (handlesAttribute != null)
{
builder.RegisterType(handler).AsImplementedInterfaces().Keyed(handlesAttribute.Value, typeToRegister);
}
}
}
}
With assemblesToScanBeing:
var assembliesToScan = AppDomain.CurrentDomain.GetAssemblies();
When I run the web app, I get the following error:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
I know what the error is, and have fixed it many times. However if I just refresh the page after ~10-15 seconds, the error no longer appears and the web app is okay to use from then on.
When I looked into this further and inspected LoaderExceptions, the following type was failing to load "Viper.ViewModels.Users.ADUserViewModel". This is where it get's weird. That file does NOT exist, anywhere. Not by searching for files, not even by searching for text. I found out it was a class that was created on a completely separate branch that was never actually merged into master (using GIT).
Now to make it even more weird, if I add in the class ADUserViewModel to Viper.ViewModels/Users folder and even leave the class completely empty. The project runs without any issues/errors whatsoever.
I mean, I could leave the empty class there, it's not doing any harm. But it will really bug me that A) It's unnecessary and B) I don't actually know why this is happening.
Any ideas would be greatly appreciated and put my mind at rest! I'm not sure what code can be posted to help explain this better, but more than happy to provide some if needed.

Roslyn - determine project excluded from build configuration

I am trying to figure out which project is enabled/disabled in respective build configuration/platform setup. Where could I find this "project.BuildsInCurrentConfiguration" information please?
var properties = new Dictionary<string, string>
{
{ "Configuration", "Debug" },
{ "Platform", "x86"}
};
MSBuildWorkspace workspace = MSBuildWorkspace.Create(properties);
workspace.LoadMetadataForReferencedProjects = true;
Solution solution = workspace.OpenSolutionAsync("someSolution.sln").Result;
foreach (Project project in solution.Projects)
Console.Out.WriteLine($"{project.OutputFilePath} is enabled in this build setup: {project.BuildsInCurrentConfiguration}");
workspace.CloseSolution();
I would have thought I wouldn't be offered the projects that are not part of the picked configuration/platform, but solution.Projects shows me all of them regardless build setup.
I don't think Roslyn really has most of that information right now (I'm not sure if it ever would; but I would hope it would). I don't see anything related to a "configuration" for a project with the Roslyn APIs for example. That seems to be delegated to the DTE interfaces. You can get at platform type in a Roslyn project, so conceptually you could only get projects that would apply to a given type of build:
var rolsynProjects = solution.Projects
.Where(p => p.CompilationOptions.Platform == Platform.X86);
but, things like "DEBUG" configuration seem to only be available via DTE--which isn't that hard to get at. e.g.
var project = DTE.Solution.Projects
.Where(p=>p.FullName == rolsynProjects.First().FilePath).FirstOrDefault();
And from that VS project, you can get at its ConfigurationManager

Dynamically compiled project losing resources

I need to compile source code of big project dynamically and output type can be Windows Application or Class Library.
Code is nicely executed and its possible to make .dll or .exe files, but problem is that, when I'm trying to make .exe file - it's losing resources like project icon. Result file doesn't include assembly information to.
Any way to solve this? (Expected result should be the same, that manual Build function on project file in Visual Studio 2015).
Thank you!
var workspace = MSBuildWorkspace.Create();
//Locating project file that is WindowsApplication
var project = workspace.OpenProjectAsync(#"C:\RoslynTestProjectExe\RoslynTestProjectExe.csproj").Result;
var metadataReferences = project.MetadataReferences;
// removing all references
foreach (var reference in metadataReferences)
{
project = project.RemoveMetadataReference(reference);
}
//getting new path of dlls location and adding them to project
var param = CreateParamString(); //my own function that returns list of references
foreach (var par in param)
{
project = project.AddMetadataReference(MetadataReference.CreateFromFile(par));
}
//compiling
var projectCompilation = project.GetCompilationAsync().Result;
using (var stream = new MemoryStream())
{
var result = projectCompilation.Emit(stream);
if (result.Success)
{
/// Getting result
//writing exe file
using (var file = File.Create(Path.Combine(_buildPath, fileName)))
{
stream.Seek(0, SeekOrigin.Begin);
stream.CopyTo(file);
}
}
}
We never really designed the workspace API to include all the information you need to emit like this; in particular when you're calling Emit there's an EmitOptions you can pass that includes, amongst other things, resource information. But we don't expose that information since this scenario wasn't hugely considered. We've done some of the work in the past to enable this but ultimately never merged it. You might wish to consider filing a bug so we officially have the request somewhere.
So what can you do? I think there's a few options. You might consider not using Roslyn at all but rather modifying the project file and building that with the MSBuild APIs. Unfortunately I don't know what you're ultimately trying to achieve here (it would help if you mentioned it), but there's a lot more than just the compiler invocation that is involved in building a project. Changing references potentially changes other things too.
It'd also be possible, of course, to update MSBuildWorkspace yourself to pass this through. If you were to modify the Roslyn code, you'll see we implement a series of interfaces named "ICscHostObject#" (where # is a number) and we get passed the information from MSBuild to that. It looks like we already stash that in the command line arguments, so you might be able to pass that to our command line parser and get the data back you need that way.

Categories