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/
Related
I'm trying to use the new ObservableProperty attribute from the CommunityToolkit.MVVM. Any time I add it, I get 17 errors such as "The type MainViewModel already contains a definition for FileToPlay", or "Type MainViewModel already defines a member called 'OnFileToPlayChanging' with the same parameter types". These are all in the MainViewModel.g.cs file.
I'm using VS 2022 Community, and the project has a WPF Application project template targeting .NET6.
Sample code that generates the error is:
namespace CorePlayer.ViewModel
{
public partial class MainViewModel : ObservableObject
{
[ObservableProperty]
private string? fileToPlay;
}
}
Anyone have any idea what I could be doing wrong?
Thanks
I had this exact same problem. Searching for an answer led me to this question.
My application is a WPF app on .NET Core 3.1.
I fixed it by following the guidance at the end of this YouTube video, .NET Community Toolkit.
I chose my second project as a .NET Standard 2.1 project.
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>10.0</LangVersion>
</PropertyGroup>
After updating Visual Studio to version 17.4.0 preview 6 (and making sure the class was marked "partial"), it now works.
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.
I am developing UWP app in xamarin. The application works on IOS, Mac , Android, Windows. I have created UWP project in it according to the tutorial given in developer.xamarin.com. But it giving error saying Accessibility.App namespace not found.
Here is my code:
namespace Accessibility.UWP
{
public sealed partial class MainPage
{
public MainPage()
{
this.InitializeComponent();
this.LoadApplication(new Accessibility.App());
}
}
}
According to your description, the app can't see Accessibility.App. As you claim that Android and iOS projects work there are two things that can cause the problem:
you don't have the reference to your Shared/PCL project in your UWP project (most likely).
you have possibly changed the namespace / class name in the Shared/PCL project to something else than Accessibility.App
This is usually caused by missing reference to the shared project or class library where Xamarin.Forms App class resides. From the description this project should be called Accessibility.
Right-click the UWP project select Add, Reference... then in Solution tab select the Accessibility project.
Also it might happen that the UWP project didn't pick up on the reference, so restarting Visual Studio might help as well.
If all fails, you can try to use class name binding with using. On top of the source code file add:
using FormsApp = Accessibility.App;
And then in code use:
this.LoadApplication(new FormsApp());
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);
}
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>