Roslyn Visual Studio 2017, Microsoft.CodeAnalysis Version 2.6.1 - visual-studio

We are programming a Roslyn Visual Studio 2017 plugin on the platform Microsoft.CodeAnalysis 2.6.1.
Actual state:
We created a VSIX project and programmed some simple DiagnosticAnalyzer subclasses, which were loaded correctly after adding the assets to the source.extension.vsixmanifest file (see https://msdn.microsoft.com/en-us/library/ee943167.aspx).
Current state:
Our plugin should also be able to do some simple refactorings. So we created a subclass of CodeFixProvider.
Unfortunately the hook methods of the CodeFixProvider never gets called. Does somebody know why?
Thats my code:
[ExportCodeFixProvider(LanguageNames.CSharp), Shared]
public sealed class BooleanComparisonCodeFixProvider : CodeFixProvider
{
public override ImmutableArray FixableDiagnosticIds {
get { // never gets called }
}
public override Task RegisterCodeFixesAsync(CodeFixContext context)
{
// never gets called
}
public sealed override FixAllProvider GetFixAllProvider()
{
// never gets called
}
}
Greets MjeOsX

You need to add [ExportCodeFixProvider(LanguageNames.Whatever)] to export your class to Visual Studio's MEF container.

Related

Xamarin.iOS does not compile - CS2011 Error opening Response File

I edited a storyboard in Xcode's Interface Builder, and assigned the View Controllers from Interface Builder.
Now when I attempt to compile the project I receive the following compiler error:
/absolute/path/to/project/MyProject.iOS/CSC: Error CS2011: Error opening response file '/absolute/path/to/project/MyProject.iOS/Views/Root/RootController.cs' (CS2011) (MyProject.iOS)
/absolute/path/to/project/MyProject.iOS/CSC: Error CS2011: Error opening response file '/absolute/path/to/project/MyProject.iOS/Views/Root/RootController.designer.cs' (CS2011) (MyProject.iOS)
I don't know if this could be related, but when I create the ViewController from Visual Studio for Mac [Community] (7.2.2 build 11) it also creates a .xib file for the ViewController, that I just delete as I only want the ViewController.
Anyway, is there anything I should do differently when editing storyboards from Xcode? Or is there something I'm missing when creating a new UIViewController from Visual Studio?
Here is the file Visual Studio generates for the UIViewController
public partial class RootController : UIViewController
{
public RootController() : base("RootController", null)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
}
Ok, I'm going to post the answer to this as I just found out what was causing it.
In my solution I have my Views folder named #Views so it sits at the top of the folder structure. Visual Studio doesn't seem to like that name #Views specifically the # and thus strips it out, which makes it an invalid path when when it goes to look for the file.
So it's my poor choice of naming that caused my own issue.

xamarin android uitest theme style conflicts

Recently I asked a question over trying to get my theme recognized within the android test project: Unit testing a Xamarin Forms Android specific code project
I'm not running into a conflict that shows up within xunit / nunit as the testing strategy. I feel like it's because the FormsAppCompatActivity with an older activity type, but I'm new to Xamarin and am unsure on how to approach this.
I get a lot of these type of errors:
Attribute "layout_anchorGravity" already defined with incompatible format.
The full list of the similar Attribute errors is:
fabSize
tabMode
expandedTitleGravity
layout_scollFlags
layout_collapseMode
collapsedTitleGravity
tabGravity
showDividers
displayOptions
showAsActions
actionBarSize
finally I have the addition error:
Found tag styles where item is expected
//Within the Android Forms project, I have this inheritance:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity {
// typical code
}
//within the Android UITest project
public class MainActivity : Xunit.Runners.UI.RunnerActivity {
// tests can be inside the main assembly
AddTestAssembly(Assembly.GetExecutingAssembly());
AddExecutionAssembly(typeof(ExtensibilityPointFactory).Assembly);
// or in any reference assemblies
//AddTestAssembly(typeof(PortableTests).Assembly);
// or in any assembly that you load (since JIT is available)
#if false
// you can use the default or set your own custom writer (e.g. save to web site and tweet it ;-)
Writer = new TcpTextWriter ("10.0.1.2", 16384);
// start running the test suites as soon as the application is loaded
AutoStart = true;
// crash the application (to ensure it's ended) and return to springboard
TerminateAfterExecution = true;
#endif
// you cannot add more assemblies once calling base
base.OnCreate(bundle);
}

How to compile Xamarin Forms from source and use the assemblies?

I downloaded a copy of the current Xamarin Forms master branch, compiled it, and then I added these compiled assemblies as references to a test project:
Xamarin.Forms.Core
Xamarin.Forms.Platform
Xamarin.Forms.Platform.Android
Xamarin.Forms.Xaml
The test project was created using the Visual Studio Xamarin Forms project template, the only thing I modified is the references in the Core.csproj and Android.csproj to point to the compiled assemblies.
I used the first 3 from the bin\debug\ folder of the Xamarin.Forms.Platform.Android project, and the last one from the Xamarin.Forms.Xaml bin\debug folder.
I run the test project, and it runs fine, I can see the label from the default generated code "Welcome to Xamarin Forms!"
Next, I just modified the MainPage like this:
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new ContentPage());
}
}
When I run the app, it gives me an error
System.ArgumentException: element is not of type Xamarin.Forms.View
Parameter name: element
thrown on this line:
void IVisualElementRenderer.SetElement(VisualElement element)
{
if (!(element is TElement))
throw new ArgumentException("element is not of type " + typeof(TElement), nameof(element));
SetElement((TElement)element);
}
which is strange.
The type of the element is Xamarin.Forms.NavigationPage and the stack trace is
Can someone help me running the test project with the compiled assemblies?
UPDATE #1:
The 2nd entry in the call stack shows that it's not able to get the registered renderer(NavigationPageRenderer) for the NavigationPage element and instead it's creating a default renderer(DefaultRenderer), which can't handle the type of element(NavigationPage) so it's throwing the exception I see.
So it appears that for NavigationPage, it doesn't find its renderer(NavigationPageRenderer) in the Registrar.
public static IVisualElementRenderer CreateRenderer(VisualElement element)
{
UpdateGlobalContext(element);
IVisualElementRenderer renderer = Registrar.Registered.GetHandler<IVisualElementRenderer>(element.GetType()) ?? new DefaultRenderer();
renderer.SetElement(element);
return renderer;
}
My feeling is there's a build step I'm not aware about when building Xamarin Forms.
Its crashing as you are calling InitializeComponent on something which doesn't derive from a Forms.Page (i.e. ContentPage etc).
The application itself is not a Page, if you had a page, lets call it 'MyCustomPage' which has some Xaml behind the class would look something like this:
public partial class MyCustomPage : ContentPage
{
public MyCustomPage()
{
InitializeComponent ();
// Some other setup...
}
}
Then in your App constructor you would call
MainPage = new MyCustomPage();
Since you are creating a blank content page from the root of your app, you do not need to call InitializeComponent.
Hope this helps.
You also need to reference
Xamarin.Forms.Platform.Android (Forwarders)
from your Android project.

What is the minimal working IVsTextViewCreationListener implementation?

I created a VISX project, and wrote this piece of code:
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
using System.ComponentModel.Composition;
namespace MyExtension
{
[Export(typeof(IVsTextViewCreationListener))]
public class Main : IVsTextViewCreationListener
{
public void VsTextViewCreated(IVsTextView textViewAdapter)
{
}
}
}
If I put a breakpoint inside the VsTextViewCreated method, Visual Studio informs me that it will never be hit. Opening files in the second instance of Visual Studio that launches in the debugger indeed does not trigger it.
What am I doing wrong?
You need to specify ContentType and TextViewRole for your class:
[Microsoft.VisualStudio.Utilities.ContentType("text")]
[Microsoft.VisualStudio.Text.Editor.TextViewRole(Microsoft.VisualStudio.Text.Editor.PredefinedTextViewRoles.Editable)]
Also don't forget to declare a MefComponent asset in your extension manifest:
And make sure in .csproj:
<IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer>

Automatically load a VSPackage visual studio extension when a solution loads?

I have created a visual studio extension and bound behaviour to build events. I want it to load automatically when the user loads a solution. How do I do that?
You need to use the attribute ProvideAutoLoadAttribute on your class that inherits from Package and pass it the guid that represents UI context where a solution is loaded:
[PackageRegistration(UseManagedResourcesOnly = true)]
// This attribute is used to register the information needed to show this package
// in the Help/About dialog of Visual Studio.
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[Guid(GuidList.guidHookIntoBuildEventsPkgString)]
[ProvideAutoLoadAttribute("{F1536EF8-92EC-443C-9ED7-FDADF150DA82}")]
public sealed class HookIntoBuildEventsPackage : Package
{
...
}
More UI contexts can be found here:
http://sandrinodimattia.net/blog/posts/some-clarity-on-auto-loading-visual-studio-2010-extensions/

Resources