How do I extend the project properties screen in Visual Studio? - visual-studio-2010

When u view a project properties in Visual Studio u get a number of tabs.
The standard ones are "Application", "Build", "Build Events" etc.
It is also possible to add custom tabs. For example view the properties of a WebApplication or a VSIX project you get different (extra) tabs.
So how do I write a VSIX addin that adds a custom tab to the project properties windows?

Check out this article: How to: Add and Remove Property Pages.
You create a page like so:
class DeployPropertyPage : Form, Microsoft.VisualStudio.OLE.Interop.IPropertyPage
{
. . . .
//Summary: Return a stucture describing your property page.
public void GetPageInfo(Microsoft.VisualStudio.OLE.Interop.PROPPAGEINFO[] pPageInfo)
{
PROPPAGEINFO info = new PROPPAGEINFO();
info.cb = (uint)Marshal.SizeOf(typeof(PROPPAGEINFO));
info.dwHelpContext = 0;
info.pszDocString = null;
info.pszHelpFile = null;
info.pszTitle = "Deployment"; //Assign tab name
info.SIZE.cx = this.Size.Width;
info.SIZE.cy = this.Size.Height;
if (pPageInfo != null && pPageInfo.Length > 0)
pPageInfo[0] = info;
}
}
And you register it like so:
[MSVSIP.ProvideObject(typeof(DeployPropertyPage), RegisterUsing = RegistrationMethod.CodeBase)]

Related

ItemEvent in SAP B1 SDK with a SAP form created in Visual Studio 2015

I truly really need your help.
I want to be able to deal with a Click on an Item on my Form which has been created in Visual Studio 2015
this is my Main Methode :
static void Main(string[] args)
{
try
{
Application oApp = null;
if (args.Length < 1)
{
oApp = new Application();
}
else
{
oApp = new Application(args[0]);
}
Menu MyMenu = new Menu();
MyMenu.AddMenuItems();
oApp.RegisterMenuEventHandler(MyMenu.SBO_Application_MenuEvent);
Application.SBO_Application.AppEvent += new SAPbouiCOM._IApplicationEvents_AppEventEventHandler(SBO_Application_AppEvent);
oApp.Run();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
and this code is automatically generated by Visual studio when i creat a new SAP B1 Project.
now i want to add an ItemEvent to handle some klick events on some Forms.
when i add this to the code :
Application.SBO_Application.ItemEvent += new SAPbouiCOM._IApplicationEvents_ItemEventEventHandler(SBO_Application_ItemEvent);
und of course the Methode SBO_Application_ItemEvent then i got a compiler error in this code line that an object reference is requiered for non-static fields...
what did i miss?
I just want to be able to do something when the User clicks on the Grid in my Form.
A Method to add a click event to a grid on a custom user form,
using Visual Studio and SAP BUSINESS ONE STUDIO:
Open the .b1f file in visual studio designer.
an example form:
Click on the Grid you wish to add the event for and navigate to the properties window
Click the lightening symbol to see the events
Double click the space next to your Desired Event
visual studio should then add the code for the event as required, something similar to the below should appear in code:
private void docRowGrid_ClickBefore(object sboObject, SAPbouiCOM.SBOItemEventArg
pVal, ref bool BubbleEvent)
{
}

AppLink Xamarin forms not indexing

I was wondering if you can help, it's literally driving me crazy. I'm trying to integrate deeplinking into my app following Lightning lecture and it simply doesn't work. I can't even get my items to show in spotlight search.
So I created a completely new project, all default New solution->forms app.
The default app is a todo list app, where I've added just two methods
AppLinkEntry GetAppLink(ItemDetailViewModel item)
{
var pageType = GetType().ToString();
var pageLink = new AppLinkEntry
{
Title = item.Title,
Description = item.Title,
AppLinkUri = new Uri(string.Format("http://website1120180225101729.azurewebsites.net/?id={0}",item.Title.Replace(" ","") ), UriKind.RelativeOrAbsolute),
IsLinkActive = true,
Thumbnail = ImageSource.FromFile("xamarin_logo.png")
};
return pageLink;
}
protected override void OnAppearing()
{
appLink = GetAppLink(BindingContext as ItemDetailViewModel);
if (appLink != null)
{
appLink.IsLinkActive = true;
Application.Current.AppLinks.RegisterLink(appLink);
}
}
Please see the print screen below. It registers an app link
But when I minimise the app and got to spotlight search it doesn't appear there
You should also add the Associated Domains in your Entitlements.plist. Open your Entitlements.plist configure it like:
After setting it, we should add this custom entitlements to our project:
Right click the iOS project => Properties => iOS Bundle Signing => Custom Entitlements.
Choose the Entitlements.plist we set above.

How to automate Package Manager Console in Visual Studio 2013

My specific problem is how can I automate "add-migration" in a build process for the Entity Framework. In researching this, it seems the mostly likely approach is something along the lines of automating these steps
Open a solution in Visual Studio 2013
Execute "Add-Migration blahblah" in the Package Manager Console (most likely via an add-in vsextention)
Close the solution
This initial approach is based on my own research and this question, the powershell script ultimately behind Add-Migration requires quite a bit of set-up to run. Visual Studio performs that setup automatically when creating the Package Manager Console and making the DTE object available. I would prefer not to attempt to duplicate that setup outside of Visual Studio.
One possible path to a solution is this unanswered stack overflow question
In researching the NuGet API, it does not appear to have a "send this text and it will be run like it was typed in the console". I am not clear on the lines between Visual Studio vs NuGet so I am not sure this is something that would be there.
I am able to find the "Pacakage Manager Console" ironically enough via "$dte.Windows" command in the Package Manager Console but in a VS 2013 window, that collection gives me objects which are "Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowBase". If there is a way stuff text into it, I think I need to get it to be a NuGetConsole.Implementation.PowerConsoleToolWindow" through reviewing the source code I am not clear how the text would stuffed but I am not at all familiar with what I am seeing.
Worst case, I will fall back to trying to stuff keys to it along the lines of this question but would prefer not to since that will substantially complicate the automation surrounding the build process.
All of that being said,
Is it possible to stream commands via code to the Package Manager Console in Visual Studio which is fully initialized and able to support an Entity Framework "add-migration" command?
Thanks for any suggestions, advice, help, non-abuse in advance,
John
The approach that worked for me was to trace into the entity framework code starting in with the AddMigrationCommand.cs in the EntityFramework.Powershell project and find the hooks into the EntityFramework project and then make those hooks work so there is no Powershell dependency.
You can get something like...
public static void RunIt(EnvDTE.Project project, Type dbContext, Assembly migrationAssembly, string migrationDirectory,
string migrationsNamespace, string contextKey, string migrationName)
{
DbMigrationsConfiguration migrationsConfiguration = new DbMigrationsConfiguration();
migrationsConfiguration.AutomaticMigrationDataLossAllowed = false;
migrationsConfiguration.AutomaticMigrationsEnabled = false;
migrationsConfiguration.CodeGenerator = new CSharpMigrationCodeGenerator(); //same as default
migrationsConfiguration.ContextType = dbContext; //data
migrationsConfiguration.ContextKey = contextKey;
migrationsConfiguration.MigrationsAssembly = migrationAssembly;
migrationsConfiguration.MigrationsDirectory = migrationDirectory;
migrationsConfiguration.MigrationsNamespace = migrationsNamespace;
System.Data.Entity.Infrastructure.DbConnectionInfo dbi = new System.Data.Entity.Infrastructure.DbConnectionInfo("DataContext");
migrationsConfiguration.TargetDatabase = dbi;
MigrationScaffolder ms = new MigrationScaffolder(migrationsConfiguration);
ScaffoldedMigration sf = ms.Scaffold(migrationName, false);
}
You can use this question to get to the dte object and from there to find the project object to pass into the call.
This is an update to John's answer whom I have to thank for the "hard part", but here is a complete example which creates a migration and adds that migration to the supplied project (project must be built before) the same way as Add-Migration InitialBase -IgnoreChanges would:
public void ScaffoldedMigration(EnvDTE.Project project)
{
var migrationsNamespace = project.Properties.Cast<Property>()
.First(p => p.Name == "RootNamespace").Value.ToString() + ".Migrations";
var assemblyName = project.Properties.Cast<Property>()
.First(p => p.Name == "AssemblyName").Value.ToString();
var rootPath = Path.GetDirectoryName(project.FullName);
var assemblyPath = Path.Combine(rootPath, "bin", assemblyName + ".dll");
var migrationAssembly = Assembly.Load(File.ReadAllBytes(assemblyPath));
Type dbContext = null;
foreach(var type in migrationAssembly.GetTypes())
{
if(type.IsSubclassOf(typeof(DbContext)))
{
dbContext = type;
break;
}
}
var migrationsConfiguration = new DbMigrationsConfiguration()
{
AutomaticMigrationDataLossAllowed = false,
AutomaticMigrationsEnabled = false,
CodeGenerator = new CSharpMigrationCodeGenerator(),
ContextType = dbContext,
ContextKey = migrationsNamespace + ".Configuration",
MigrationsAssembly = migrationAssembly,
MigrationsDirectory = "Migrations",
MigrationsNamespace = migrationsNamespace
};
var dbi = new System.Data.Entity.Infrastructure
.DbConnectionInfo("ConnectionString", "System.Data.SqlClient");
migrationsConfiguration.TargetDatabase = dbi;
var scaffolder = new MigrationScaffolder(migrationsConfiguration);
ScaffoldedMigration migration = scaffolder.Scaffold("InitialBase", true);
var migrationFile = Path.Combine(rootPath, migration.Directory,
migration.MigrationId + ".cs");
File.WriteAllText(migrationFile, migration.UserCode);
var migrationItem = project.ProjectItems.AddFromFile(migrationFile);
var designerFile = Path.Combine(rootPath, migration.Directory,
migration.MigrationId + ".Designer.cs");
File.WriteAllText(designerFile, migration.DesignerCode);
var designerItem = project.ProjectItems.AddFromFile(migrationFile);
foreach(Property prop in designerItem.Properties)
{
if (prop.Name == "DependentUpon")
prop.Value = Path.GetFileName(migrationFile);
}
var resxFile = Path.Combine(rootPath, migration.Directory,
migration.MigrationId + ".resx");
using (ResXResourceWriter resx = new ResXResourceWriter(resxFile))
{
foreach (var kvp in migration.Resources)
resx.AddResource(kvp.Key, kvp.Value);
}
var resxItem = project.ProjectItems.AddFromFile(resxFile);
foreach (Property prop in resxItem.Properties)
{
if (prop.Name == "DependentUpon")
prop.Value = Path.GetFileName(migrationFile);
}
}
I execute this in my project template's IWizard implementation where I run a migration with IgnoreChanges, because of shared entites with the base project. Change scaffolder.Scaffold("InitialBase", true) to scaffolder.Scaffold("InitialBase", false) if you want to include the changes.

How do I Edit a .cs file in a Add-In Project using DTE

I'm trying to write my first add-in for vs2010, but im struggling.
I have a assembly that generates lots of cs files. I want my plugin to add new files to the select project or if the files exist, overwrite them.
I'm having 2 problems:
When I add a new file, how do I add it to a sub folder inside the project? I seem to only be able to add to the root of the project.
If a cs file exists, how do I clear its content? Im using the EnvDTE.TextDocument & EnvDTE.EditPoint interfaces. But every time I try and iterate through the document clearing lines, I get a COM error "Exception from HRESULT: 0x80041001".
I dont want to delete the file and add a new file if I can help it. Due to the logging on source control.
textDoc = (TextDocument) document.Object("TextDocument");
EditPoint editPoint = (EditPoint)textDoc.StartPoint.CreateEditPoint();
EditPoint endPoint = (EditPoint)textDoc.EndPoint.CreateEditPoint();
editPoint.Delete(endPoint);
No looping needed and your editpoint never moves from the first position.
Well i've got a one way of doing this working.
// Get an instance of the currently running Visual Studio IDE.
var dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.10.0");
//I store the list of projects in dte2.Solution.Projects in a combobox
EnvDTE.Project project = (EnvDTE.Project)projectList.SelectedValue; //I get my projects out of a combobox
foreach (ProjectItem projectItem in project.ProjectItems)
{
Document document;
try
{
projectItem.Open();
document = projectItem.Document;
}
catch(Exception)
{
Console.WriteLine("failed to load document");
continue;
}
if (document == null)
{
continue;
}
if (document.Name == "Class1.cs") //whatever file your after
{
TextDocument editDoc = (TextDocument) document.Object("TextDocument");
EditPoint objEditPt = editDoc.CreateEditPoint();
objEditPt.StartOfDocument();
document.ReadOnly = false;
while (!objEditPt.AtEndOfDocument)
{
objEditPt.Delete(objEditPt.LineLength);
objEditPt.LineDown(1);
}
objEditPt.DeleteWhitespace(vsWhitespaceOptions.vsWhitespaceOptionsHorizontal);
objEditPt.DeleteWhitespace(vsWhitespaceOptions.vsWhitespaceOptionsVertical);
Console.WriteLine("saving file {0}", document.FullName);
document.Save(document.FullName);
}
}

Creating a new site sharepoint 2010 under parent site with my custom template Programatically using visual studio 2010

I have a parent website under which i want to create subsites on the fly using visual studio 2010.
The subsites which i want to create have a common stuructre(in temrs of lists & custom).
So i saved the template in sharepoint 2010,it becomes wsp and goes into soution gallery.
Now how do i use this template say mytemplate.wsp,to create site in visual studio.
i tried this
using (SPSite site = new SPSite ("http://infml01132:5566/sites/VRND " ))
{
using (SPWeb web = site.OpenWeb())
{
SPWebTemplateCollection myTemplates = site.GetCustomWebTemplates(Convert .ToUInt32(web.Locale.LCID));
//SPWebTemplateCollection temlates1 = site.GetCustomWebTemplates(1033);
//SPWebTemplateCollection temlates = site.GetWebTemplates(1033);
//SPCustomWebTemplate
SPWebTemplate subsitetemplate = myTemplates["vrndtmpl" ];
web.Webs.Add("subsite1" , "rnd subsite1" , "subsite description changed" , Convert .ToUInt16(1033), subsitetemplate, false , false );
}
}
But i dont get my template in mytemplates collection.
Thanks
We are using this code to retrieve site template by it's name:
private SPWebTemplate GetSiteTemplate(SPSite site, string templateName, int lcid)
{
foreach (SPWebTemplate webTemplate in site.GetWebTemplates(lcid))
{
if (webTemplate.Name.ToLower().Contains(templateName.ToLower()))
{
return webTemplate;
}
}
return null;
}
It is 100% works.
So, in your case, you should write:
using (SPSite site = new SPSite ("http://infml01132:5566/sites/VRND"))
{
using (SPWeb web = site.OpenWeb())
{
SPWebTemplate subsitetemplate = GetSiteTemplate(site, "vrndtmpl", 1033);
web.Webs.Add("subsite1" , "rnd subsite1" , "subsite description changed" , uint(1033), subsitetemplate, false , false);
}
}
Also, please, ensure, that you have deployed your site template under SiteTemplates directory, and the corresponding webtemp.xml file to <14 hive>\TEMPLATE\1033\XML or deployed it through feature, as described here.

Resources