Attach VsPackage to Roslyn Instance - c#

I'm trying to create a VsPackage that makes use of the Roslyn Language Services. Under the properties of my VsPackage, I've changed the command line arguments to:
/rootsuffix Roslyn
When running the project, the instance of Visual Studio that starts up is correctly using Roslyn. (I see [Roslyn] next to the names of .cs files I have open). However, my VsPackage is not deployed to this instance of Visual Studio.
I have opened up the SyntaxVisualizerExtension VsPackage that ships with Roslyn and compiled/run that. It correctly deploys to Visual Studio using Roslyn. I've looked through the project properties and references and nothing has stood out to me as missing.
The steps I'm taking are :
File > New Project > Visual Studio Package
Create with Tool Window
Open Project properties, change /rootsuffix Exp to /rootsuffix Roslyn
Add references to Roslyn .dlls
Run project.
In theory, I could probably strip down the SyntaxVisualizerExtension Package, but I'd like to know the proper way to create a VsPackage for the Roslyn instance.

There's no UI setting to control what the property is. Edit your project file in Notepad (or unload the project in VS and then right click and choose "edit"), and add this line:
<VSSDKTargetPlatformRegRootSuffix>Roslyn</VSSDKTargetPlatformRegRootSuffix>
into the appropriate PropertyGroup. Look in the projects created via any of the Roslyn templates for an example.

Related

Visual Studio will automatically make functional changes to the following projects in order to open them

I decompiled a EXE and now when I try to open it. I get
One-way upgrade
Visual Studio will automatically make functional changes to the following projects in order to open them. You will not be able to open these projects in the version of Visual Studio in which they were originally created.
If I click okay I get ~250 errors
I found that need to open .csproj file and delete lines with
ProjectMode, TargetOfficeVersion, FileUpgradeFlags, UpgradeBackupLocation or OldToolsVersion. But I don't have in .csproj any lines like this.
Is there a way to fix this. Or at least a way to find what Version of Visual Studio was using the author ?

VSIX Project Context Menu

I'm trying to create a Visual Studio 2017 extension, just for fun and to learn how VS extensibility works.
My extension must be usable from the Solution Explorer tab as a context menu button, but I would like to include it at a menu level that isn't root.
My goal is to put it in the "Add" sub-menu, but at the moment I'm only able to put it at root level (when you right-click the Project item, the menu entry is shown as the last of the context menu control).
How can I move it under the "Add" node?
Can it be done from the CommandPlacement tags I have configured in my .vsct file?
Use as parent of your command the IDG_VS_CTXT_PROJECT_ADD_ITEMS group id. If you are using CommandPlacement it would be:
<CommandPlacement guid="..." id="..." priority="0x0001" >
<Parent guid="guidSHLMainMenu" id="IDG_VS_CTXT_PROJECT_ADD_ITEMS"/>
</CommandPlacement>
Remember:
The parent of a group can be another group, a menu, a toolbar, a context menu, etc. either created by your extension or an existing one of VS, identified by prefix "IDM_". See GUIDs and IDs of Visual Studio menus and GUIDs and IDs of Visual Studio toolbars.
The parent of a command is always a group, never a menu, context menu or toolbar. The group can be new (created by your extension) or an existing group of Visual Studio, identified by prefix "IDG_". You have some built-in Visual Studio groups in the links above, but for a more exhaustive list install the ExtensionTools extension (Mads Kristensen) that provides intellisense in the .vsct file or check the source code of its VsctBuiltInCache.cs file.
I think and hope this might help, though it is a general answer and not a specific one. Learn by example.
I also hope the WiX authors won't mind, but I believe the source for their Visual Studio integration component "WiX Votive" is here: https://github.com/wixtoolset/VisualStudioExtension.
There is also this: https://github.com/wixtoolset/VisualStudio.wixext. I am not sure what this is to be honest. I should, but I don't. Mr.Arnson - I summon theee (WiX developer - The Matrix's got you).
WiX Votive - VS Integration is part of the overall WiX Toolset - which is a Windows Installer deployment solution capable of compiling MSI files from XML markup. MSI files are the binary deployment files used by Windows Installer for deployment on Windows.
If of interest you 1) download and install WiX itself (currently 3.11.1), and 2) download and install the correct Visual Studio integration (the marketplace links underneath the main download) making sure you get the correct version for your Visual Studio version - of course. Both downloads from the same link (or use the Visual Studio marketplace).
Here are some further details: WiX quick-overview.

Cannot create .apk file after introducing Crypto Obfuscator into Xamarin.Android project

I have a task of obfuscating my Xamarin Android project (let call it AndrProj) together with libraries it references: two PCL (let's call them PCL1 and PCL2) and Android library (AndrLib). PCL2 and AndrLib also have references to PCL1.
I was inspired by this article and decided to try Crypto Obfuscator For .Net v2015 demo version for my purposes.
I used its 'Visual Studio Project Integration Wizard'. PCL1 was set as 'First project' and AndrProj as 'Last project'. Only default settings were used for the beginning. Now when I build my project everything is perfect. Dll's in \bin\Release folder are obfuscated.
I would be completely happy if I could actually create an .apk file and try it on the Android device. But when I select Build -> Archive for Publishing in Xamarin Studio, after some time I see 'Build FAILED' and
Error occurred while obfuscation: - The assembly 'AndrLib' is
already obfuscated with Crypto Obfuscator. If you have run the Visual Studio Project Integration Wizard on your Visual Studio projects, you cannot obfuscate from the Crypto Obfuscator UI unless you first disable automatic obfuscation for this project from Crypto Obfuscator's 'Project' menu --> 'Enable/Disable Visual
Studio Integration' and Rebuild your solution in Visual Studio to
produce unobfuscated assemblies.
I also tried 'Export Android Package (.apk)' from Visual Studio 2013, but it gives less output and still does not create .apk.
I believe it complains only about AndrLib because it goes first alphabetically among PCL1, PCL2 and AndrLib. And more global problem is that creating .apk forces all assemblies to be obfuscated one more time. Is there any way to skip this second time obfuscation? Or to ignore this kind of problem?
Well, the solutions was pretty simple: I had to use MSBuild.exe directly with target SignAndroidPackage instead of creating .apk from IDE.
Here is an email from technical support regarding the described problem (may be useful for someone):
If your solution fails to build after doing MSBuild Integration, try the following:
Change the build output log verbosity as follows:
Visual Studio Tools menu --> Options --> Projects And Solutions --> Build and Run --> MSBuild Project Build Output Verbosity, set this to Detailed.
Now check the Visual Studio Output window for any hints or more information regarding the cause of the error.
Change the number of threads used by MSBuild to 1 as follows:
Visual Studio Tools menu --> Options --> Project And Solutions --> Build And Run --> Maximum number of parallel threads : set this to 1.
If you get an error message similar to "The assembly 'XYZ' is already obfuscated with Crypto Obfuscator..." when you Run (CTRL+F5) or Debug (F5) your solution, then try doing a Clean ( Visual Studio Build menu --> Clean menu item) and then do the Run (CTRL+F5) or Debug (F5).
Build failure can also occur if you ran the wizard multiple times, each time selecting a different "first" project. This problem usually presents itself via a "file not found" error in the build log/output. To solve this problem, start from clean non-integrated .csproj/.vbproj files (the wizard copies the original non-integrated project files to a .backup_%timestamp% extension before modifying the project files; alternately you can open the .csproj/.vbproj files in a text editor and remove the XML added by the wizard which can be found towards the end of the file). Then run the wizard again specifying the correct first and last projects.
I had problems Archiving and the problem went away after I downgraded Visual Studio 2017 Professional from 15.9.9 to 15.7.6.

Visual Studio user-defined property sheet macros in C#

I have inherited a C# solution where the projects have a configured "Post-build command line". In this command line, there are a couple of user-defined property sheet macros that copy various output files to specific folders. However, when I build any of the projects, the macros are incorrectly defined as empty strings.
E.g.
copy "$(TargetPath)" "$(PluginPath)\$(ConfigurationName)"
The standard macros, e.g. $(TargetPath), work great, but I can't see any way of controlling the value of the user-defined macros. In the post-build step there is a "Macros >>" button which shows the standard macros, but there's no way that I can see to either to edit their values or add new, user defined macros.
It looks like the previous developer had this working, so what am I missing?
I have read that macros can be defined in .vsprops files, but only Visual C++ projects support these files. When I look in the Property Manager window, I see only the message "No Visual C++ project is loaded". (I'd expect that user-defined property sheet macros would be equally as useful in the "Post-build command line" of C++ projects as they are in C# or projects in any language.)
With a quick search I found this, it might help.
Update:
After adding the following to my .csproj project file, I can use the PluginPath as a macro in the post-build command line with copy "$(TargetPath)" "$(PluginPath)\$(ConfigurationName)" (tested in Visual Studio 2008)
...
<PluginPath>C:\apps\</PluginPath>
</PropertyGroup>
You can follow any solution as described below.
Create batch file and insert following code
set MY_INCLUDES_DIR=D:\MyIncludes
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" D:\MySolution.sln
Start Visual studio solution by double clicking this file. Advantage of this solution is all projects can use same environment variable.
Define following xml tag in visual studio project file.
<PropertyGroup>
<MY_INCLUDES_DIR>D:\MyIncludes\</MY_INCLUDES_DIR>
</PropertyGroup>
Create system environment variable named MY_INCLUDES_DIR and simply use $(MY_INCLUDES_DIR) in visual studio.

Run outputType library project

I have an ASP.NET project with outputType library, I need to run the project but it's not running. what outputType should i use to make my project run?
In order to fix the above error, right click the Solution name in Visual
Studio 2005/2008 and select Set as StartUp Project option from the popup menu.
source : Fix: A project with an Output type of Class Library cannot be started directly
Despite ASP.NET projects have Class Library type, Visual Studio can "run" these types of projects(it deploys project's output to IIS or dev server and starts web-app).
So to solve your problem you should tell Visual Studio somehow that your project is ASP.NET project. I see to ways:
1-st one - fast, straighforward, dumb, but reliable: create new "ASP.NET Web Application" project in visual studio and copy all sources to it.
2-nd - not sure that it's working, but more hack'ier and fun: open YourProject.csproj file in text editor, replace <ProjectTypeGuids ...> section by such ones, that could be found in csproj file of ASP.NET project.
Class library projects can not be run, you can debug them though. See Debugging DLL Projects
A project with an output type of class Library cannot be started directly.In order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project.Means
In VS.Net - right click on the page you want to be the initial startup page and set it to be the startup page.

Categories