Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Liesbert García Moreno
@kassius85
    Hello, I'm newbie in vsix. I need to to know how can I generate classes, interfaces and/or other elements inside a project. I tried this example: https://stackoverflow.com/questions/10126846/generate-code-from-a-visual-studio-extension, but it doesn't work for me. Thanks in advance.
Paul M Cohen
@paul1956
@kassius85 Could you be more specific. If you want to create a new file with predefined content, what you want is to create a new Template, then in File/New you select your template. If what you want to to inset some code into an existing file look at creating a Snippets. If you want to change code inside an existing file based on the tiles content then you what a VSIX and you should start with a new VSIX project from Preview 1 where there are complete working samples with tests. If you want help creating a VSIX to interact with Visual Studio review tutorials by Mads https://www.youtube.com/playlist?list=PLReL099Y5nRdG2n1PrY_tbCsUznoYvqkS
Minuri Rajapaksha
@Minuri-Rajapaksha
Hello...

I am developing an Extension for visual studio and "Solution Open" event need to be triggered once a solution is opened. Because I need to add a command to run when the solution opens.

For that I have used solutionEvents.Opened event handler and it is working fine when open solutions using below approaches

  1. using "Open Solution" dialog of visual studio
  2. Visual Studio File Menu > Recent Solutions or Projects > solution.
    But strangely solutionEvents.Opened event handler is not working when open solutions using below approaches

using .sln file double click
right clicking visual studio icon in windows task bar and click solution name to open solution.
windows start menu > visual studio 2019 > click solution name
I would like to know the reason behind that.

public void Initialize(Package package)
{
solutionEvents.Opened += SolutionEvents_SolutionOpened;
}

Appreciate any suggestions. Thanks!
Yann Duran
@yannduran
@Minuri-Rajapaksha here's a better approach: Solution Load sample
Liesbert García Moreno
@kassius85
@paul1956 I found a video in those tutorials that it's exactly what I need, thank you very much!!!
Paul M Cohen
@paul1956
@kassius85 all the code for those videos is also available under open source license for download.
Liesbert García Moreno
@kassius85
Oh great! Thanks @paul1956
Minuri Rajapaksha
@Minuri-Rajapaksha
@yannduran thanks a lot for your support. I will have a look into it and get back to you.
Matt Lacey
@mrlacey

Does anyone know what "blocked hosts" are?
My upload to the marketplace just failed with the message:

"Upload failed: There were errors during publish. Your extension contains blocked hosts"

Steve Dower
@zooba
@mrlacey At a guess, that'll be the list of supported VS types in your vsixmanifest (e.g. Community, Professional, ...). You may have an old Express edition listed?
Matt Lacey
@mrlacey
@zooba Good guess but no.
After wasting half a day experimenting, the problem was with the source of an image I included in the overview description. It seems you're not allowed to include images hosted on some domains and this includes where blogger puts images I upload to my blog.
When this is known it is easy to work around but it's a pain to discover.
Minuri Rajapaksha
@Minuri-Rajapaksha
@yannduran, the article you provided is really helpful me to troubleshoot the issue and finally was able to fix it. Thanks a lot!
Aleksandr
@aldanchenko
Hi team. Is there a way to add additional properties category to a Project Properties?
Yann Duran
@yannduran
@Minuri-Rajapaksha I'm glad you were able to solve your problem
Matt Lacey
@mrlacey
@aldanchenko I'm not 100% clear on your question but this may help https://stackoverflow.com/questions/4992511/adding-custom-information-to-csproj-files
Asj-Dev
@Asj-Dev

Hello all,

I'm trying to implement a multi process build option, which gives object-level parallelism instead of the target-level parallelism you get with /MP. It seems VCCLCompilerTool.ToolPath only gives "cl.exe" instead of an absolute path, so I guess I need to search the executable paths beforehand to find it.

Can anyone tell me how to expand variables such as "$(VC_ExecutablePath_x86)"?

Asj-Dev
@Asj-Dev
It's fine, I figured it out. :)
I initially tried a temporary hack around the issue by hard-coding the path to "cl.exe", but discovered that didn't work anyway because "cl.exe" is too fragile to be spawned directly via CreateProcess(). I was aware that was the case in general, but I'd kinda hoped it would work in a Visual Studio extension because I was assuming the environment would already be set up as necessary, but this is not the case.
Sorry, I mean "new Process()", still thinking in C++ there...
Asj-Dev
@Asj-Dev
Anyway, the full rebuild time for a 600 C++ file project dropped from a little over two minutes, to a little over two seconds, on a 64-core ThreadRipper.
So dipping my toes into extension development was very much worth the effort!
pascalgyger
@pascalgyger
I am working on an extension that is available for VS2017 and VS2019. I used to be able to switch the target version for debugging the extension. The Start split button showed usually three entries (Current Instance, VS2017 and VS2019). But now (maybe after updating to VS 16.8?) I only see the Current Instance option, and can no longer select VS2017, even though I still have VS2017 installed. Somebody else observed this? Any ideas on how to fix it?
1 reply
Aleksandr
@aldanchenko
Thanks @mrlacey!
Снимок экрана 2020-11-20 173236.png
Hi guys! Maybe someone know how to get Settings data from project properties?
Matt Lacey
@mrlacey
@aldanchenko I'd just read the settings file directly
image.png
Yann Duran
@yannduran
You can use WinForm's Properties.Settings.Default: How To: Read Settings at Run Time With C#
@aldanchenko ^^
You can use the same method in WPF (eg VS extensions): WPF: Create, write and read settings dynamically
Aleksandr
@aldanchenko
Thanks @yannduran! I'll try it 👍
Aleksandr
@aldanchenko

@yannduran maybe I'm doing something wrong, but I can read properties only for extension that I develop. I want to read properties (Settings) from current opened project in my extension.

For example, I'm developing extension SimpleExt and after developer install this SimpleExt in his Visual Studio and after this he can click a button and see some message with current project (opened project) Settings, but not SimpleExt settings.

Yann Duran
@yannduran
@aldanchenko ohhh, sorry about that, then you'd need to do something liek @mrlacey suggested
Aleksandr
@aldanchenko
Thanks @yannduran! 👍
Heras
@Heras

Hi! Maybe someone can help me out:

If I start a new VSIX project (from either VSIX Project or Empty VSIX Project) in VS2019, and start Debug, two things happen:

  1. I get the "one or more extensions were loaded using deprecated APIs" warning in the debugged VS instance,
    even though the entire project is fresh and new. I have no idea how to fix this.

  2. Debugging won't work. My breakpoints show the dreaded exclamation mark. What am I doing wrong?

Thanks!

Yann Duran
@yannduran
@Heras you'll get that warning if the package class isn't async (inherits from AsyncPackage). I don't think the template has been updated since that came into play
Heras
@Heras
@yannduran Thanks for your reply! It does seem fine however, first line is public sealed class VSPackage1 : AsyncPackage where AsyncPackage is Microsoft.VisualStudio.Shell.AsyncPackage
Yann Duran
@yannduran
is this VS 2019 v16.8.x? or the preview version v16.9.x?
it also might not be your extension that is causing that message
if you want, you can also disable that warning in Tools | Options | Extensions
image.png
Heras
@Heras
It's VS v16.8.0. And I only get the message when I debug the empty VSIX extension, not when I directly open VS. I wouldn't want others to get that message obviously ;)
Yann Duran
@yannduran

no i mean it could be another extension that's installed in the experimental instance that triggers the message

i'm just updating to v16.8.2 & v16.9.0 Previw 1.0 atm

Alessandro Triglia
@alessandrot60
Is it possible to define additional (custom) colors (appearing as "defaults" in the Format and Colors dialog) using a color package created with VsixColorCompiler? I need to define a set of different colors for each theme for some custom syntactic items. Until now, my extension has been using a set of ClassificationFormatDefinitions that are good only for the blue theme. I am trying to solve this problem. I've tried to support color settings for multiple themes by listening to the VSColorTheme.ThemeChanged event and updating the format map when the theme changes. I've checked that the format map gets updated, and the colors do change when the theme changes, but the changes to the colors are lost when I close and reopen Visual Studio. I get the new theme with the old colors. Later, I discovered what would be an elegant solution using VsixColorCompiler, but so far I haven't been able to make it work with the additional colors. I've come across 2017BlueTheme.vstheme by Mads Kristensen but it seems to contain only new settings for existing color names. If I add some new colors that match my ClassificationFormatDefinitions, nothing happens. Any suggestions?
Alessandro Triglia
@alessandrot60
Never mind, I've solved the problem.
Yann Duran
@yannduran
@alessandrot60 it'd be helpful for people if you explained HOW you solved your problem, if you care to share of course
wecan all learn from each others' experiences
Alessandro Triglia
@alessandrot60

Sure. I found two solutions and both work.

The first solution involves the use of VsixColorCompiler and is based on this answer on stackoverflow: https://stackoverflow.com/a/58884439/908196

I created an XML file like this:

<Themes>
  <Theme Name="Light" GUID="{de3dbbcd-f642-433c-8353-8f1df4370aba}">
    <Category Name="MEF Items" GUID="{75A05685-00A8-4DED-BAE5-E7A50BFA929A}">
      <Color Name="MySpecialKeyword">
        <Foreground Type="CT_RAW" Source="FF224400"/>
      </Color>
    </Category>
  </Theme>

  <Theme Name="Dark" GUID="{1ded0138-47ce-435e-84ef-9ec1f439b749}">
    <Category Name="MEF Items" GUID="{75A05685-00A8-4DED-BAE5-E7A50BFA929A}">
      <Color Name="MySpecialKeyword">
        <Foreground Type="CT_RAW" Source="FFFFCC00"/>
      </Color>
    </Category>
  </Theme>

  <Theme Name="Blue" GUID="{a4d6a176-b948-4b29-8c66-53c97a1ed7d0}">
    <Category Name="MEF Items" GUID="{75A05685-00A8-4DED-BAE5-E7A50BFA929A}">
      <Color Name="MySpecialKeyword">
        <Foreground Type="CT_RAW" Source="FF224400"/>
      </Color>
    </Category>
  </Theme>

  <Theme Name="HighContrast" GUID="{a5c004b4-2d4b-494e-bf01-45fc492522c7}">
    <Category Name="MEF Items" GUID="{75A05685-00A8-4DED-BAE5-E7A50BFA929A}">
      <Color Name="MySpecialKeyword">
        <Foreground Type="CT_RAW" Source="FF224400"/>
      </Color>
    </Category>
  </Theme>
</Themes>

Compiling the above file with VsixColorCompiler (\Program Files (x86)\Microsoft Visual Studio 14.0\VSSDK\VisualStudioIntegration\Tools\Bin\VsixColorCompiler.exe) produced a pkgdef file, which I added to source.extension.vsixmanifest as an asset.

Also, in the code there must be a corresponding ClassificationFormatDefinition that specifies the same item name ("MySpecialKeyword" in the above).


The second solution is based on subscribing to the VSColorTheme.ThemeChanged event and changing the colors of the ClassificationFormatDefinition in response to a theme change event. This solution is described in an answer on stackoverflow https://stackoverflow.com/a/48993958/908196 and was derived from an earlier solution for F#.

However, the code in the original answer had some issues, which I have discussed with the person who posted the answer (the answer may or may not have been updated when you read this).

The way it is (or was) written, the event handler correctly changes the colors when the theme changes, but all these changes are lost when the user exits Visual Studio. As a result, I was getting the new theme with the old colors. The colors would be permanently set only if I reinstalled the extension or used Clear MEF Component Cache.

The code in the answer had the following issues:

1) The GUID was wrong. The GUID to be used is {75A05685-00A8-4DED-BAE5-E7A50BFA929A}, which is the "MEF Items" category, not DefGuidList.guidTextEditorFontCategory, which is a different category.

2) The event handler should invalidate the Fonts and Colors cache for the MEF Items category by calling either fontAndColorCacheManager.ClearCache or RefreshCache before returning. This ensures that the next time Visual Studio starts, the color cache will be recreated (from the ClassificationFormatDefinitions) as soon as the information is needed, instead of Visual Studio reading the older content of the cache.


Both of the above solutions work for me. The first one puts the color information in a separate file and is perhaps more elegant, but it requires a post-build event. The second one is just C# code.

Ramon Viladomat
@Viladoman
Hi community! Does anyone know the best way to react to a change on the ActiveConfiguration? I am generating some data per configuration and I would love to update my tool windows in order to keep the data they display in sync.