Default using statements in Xamarin Studio - xamarin-studio

I want to add a default using statement to my Xamarin Studio project. Specifically, instead of the default
using System;
I want every new file to start with
using System;
using System.Collections.Generic;
Can I do that?
EDIT: I'm on a mac.

This may be of some help: Default using directives in new C# files
They are part of the template. You can amend the new class template. This should be of some help as well: http://blogs.msdn.com/b/steve/archive/2007/04/10/changing-the-default-using-directives-in-visual-studio.aspx
In case the links die, here is a snippet: "if you open %Program Files%\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\CSharp\1033\Class.zip, you can modify the class.cs file within that's used to generate all new C# source files"

Related

How to set the startup project for an asp.net core template?

I am currently creating a multi-project template, I want to distribute using a .VSIX-extension for Visual Studio. When the extension is installed the user can select my template among the others provided by Microsoft in the "Create a new project" window.
My template consists of three project:
ProjectName.Server
ProjectName.Contract
ProjectName.Client
ProjectName is the user-given name while the suffixes "Server", "Contract" and "Client" are fixed. The issue I experience is that when the users create a new project the Client-project is always selected as a startup-project by default. I want the server-project to be selected as a startup-project by visual studio. It looks like following:
The client project is not the correct startup project, but users don't know that the server project it the correct startup project, so I want to take off the selection and integrate it right into the template, so the correct startup template is selected by VS when creating the project.
I already removed the suffix "Server" from this project, so it is shown as the first project in the solution explorer and I hoped VS would then select it as the startup-project. This did not work unfortunately.
Can anyone give me a hint on how to configure the startup-project in the template?
If you have any questions don't hesitate to comment.
These configurations are stored in the Solution User Options (.suo) file.
You can refer to my steps below to try:
First, Close Visual Studio and find the folder where your solution is.
Second, Open the .sln file with a text editor, you see all your projects encapsulated in Project – EndProject lines:
Third, Cut and paste the desired default startup items into the first.
Fourth, Delete your .suo file(hidden files: Solution Folder/.vs/Solution Name Folder/v17/.suo, I use VS2022).
Finally, Open your solution in Visual Studio.
You can have a try.
You will likely need to associate a custom IWizard assembly with your project template, and then explicitly set the startup project by setting the SolutionBuild.StartupProjects to the desired project in your solution.
Once upon a time, I did this using code similar to the following:
VSProject startupProj = FindVSProject(startupProjName);
sln.SolutionBuild.StartupProjects = startupProj.Project.UniqueName;
where FindVSProject was implemented as:
private VSProject FindVSProject(string projName)
{
foreach (Project p in _dte.Solution.Projects)
if (p.Name.Equals(projName, StringComparison.CurrentCultureIgnoreCase))
return p.Object as VSProject;
return null;
}

Disable default instance of forms in VB.NET

Following this answer. Can I disable automatic instantiation? I want VS to show the error:
Reference to a non-shared member requires an object reference
Update:
When I originally wrote this answer, it was based on empirical evidence from the .vbproj file and the VB IDE and I had no reference material. Since then I have come across the article "Simplify Common Tasks by Customizing the My Namespace" published in the July 2005 MSDN Magazine (online version; full magazine edition download
This article shows to control the generation of the various My Namespace features via compilation constants. In particular it shows how to overide the MyType tag stored in the .vbproj file.
This is accomplished by setting the "Custom Constants" accessible by going to Project Properties->Compile Tab and clicking on the "Advanced Compile Options" button.
To override then MyType tag, set the custom constant _MyType.
If you want to include specific My Namespace items, you can set the pertinent constant(s) shown in the following table from the above referenced article.
The default form instances are part of the "My.Forms" member. Note that in order to prevent "My.Forms"
from being generated, set _MyType to either "Empty" or "Custom". You do not need to explicitly include _MYFORMS="False".
To use the additional constants defined in Table 5, set _MyType="Custom".
To include all the standard My Namespace items except for My.Forms, use the following constants:
_MyType="Custom", _MYAPPLICATIONTYPE="Windows", _MYCOMPUTERTYPE="Windows", _MYUSERTYPE="Windows", _MYWEBSERVICES="True"
End Update
The features enabled in Visual Studio are initialized based on the initial project template you select when creating a project. Normally, one would select the "Windows Forms App(.Net Framework) Visual Basic" template as shown below.
(Note: All images are based on VS 2017 Version 15.8.7)
This will load up a VB project environment that includes a lot of automatic code generation that supports the VB Application Framework including the "Default Form Instance" feature via additions to the My Namespace (see: My.Internals: Examining the Visual Basic My Feature. Now you could try to disable this framework via the Project Properties->Appliction Tab->Enable Application Framework checkbox, but all that does is require you to provide you own "Sub Main" implementation.
To create a project that free of all the My Namespace code generation including the the default form instances, you need to start with the "Empty Project (.Net Framework)" template.
This will create a bare-bones VB project. If you add a WinForm (Project Menu->Add Window Form) and go to the code-view and add the following:
Class Demo_NoDefaultForms
Sub ErrorOnForm1Reference()
Form1.Text = "ain't gonna work"
End Sub
End Class
You will see that the default Form1 instance is not supported.
Furthermore, all the "Application Framework" stuff in the project properties is disabled.
The project type My Namespace information is like all project information is stored in the projName.vbproj file and is stored in the <MyType> tag. Although I have never found any official documentation on this tag, the following summarizes my observations from creating various project types.
MyType Tag Value Project Type
----------------------------- ------------------------------------------------
WindowsForms Normal Windows Form App w/ Application Framework enabled
WindowsFormsWithCustomSubMain Normal Windows Form App w/ Application Framework disabled
Console Console App w/ Application Framework enabled
Custom WPF Application
Empty No My Namespace additions
Starting with the "Empty Project (.Net Framework)" template would be tedious as you would need to perform a lot of boiler-plate setup and declare a "Sub Main" each time. I recommend that you create a base project with all your own customizations and then export the project a new template (see: How to: Create project templates.

Vb.net Mobile Application

I've been assigned a school project in which we're asked to develop a survey app for device/mobile use using VB.net.
I've started learning some Visual Basic, yet I'm failing to understand the following. I've downloaded Visual Studio 2017, do I need to download something extra so that I'm able to program for a mobile device? Or what is it that I need to do? I'm quite confused, I'd really appreciate some sort of help with understanding what's going on. I've been searching on the Internet quite some time now, and all I've found is "Visual Basic for Windows Phone Developer Tools - RTW", which is a version for 2010 and I'm not quite sure if it's what I need anyway. Another thing I've found is Xamarin.
Any help will be highly appreciated and excuse me for such a dumb question.
You're probably looking for Xamarin. It lets you use C#, F# and VB.NET code to develop cross-platform apps including native apps for iOS and Android.
Note that Xamarin doesn't completely or directly support VB.NET. You'll have to do the following steps to get started:
Create a new C# solution of the type Mobile App (Xamarin.Forms). You need to have the Mobile Development with .NET workload installed for this.
In said solution, add a Visual Basic .NET Class Library (.NET Standard). After creating the project, right-click it, click Properties, and change the Default Namespace to match the existing C# project(s).
Right-click the VB.NET project again, click "Manage NuGet Packages", then install Xamarin.Forms.
After this, you will want to rename Class1.vb to App.vb. Paste the following starter / example code there:
Imports Xamarin.Forms
Public Class App
Inherits Application
Public Sub New()
Dim label = New Label With {
.HorizontalTextAlignment = TextAlignment.Center,
.FontSize = Device.GetNamedSize(NamedSize.Medium, GetType(Label)),
.Text = "Welcome to Xamarin.Forms with Visual Basic.NET"
}
Dim stack = New StackLayout With {
.VerticalOptions = LayoutOptions.Center
}
stack.Children.Add(label)
Dim page = New ContentPage
page.Content = stack
MainPage = page
End Sub
End Class
Update the Android and iOS projects so that they reference the Visual Basic .NET project(s), rather than the C# project created by the template. Right-click on the References node in the Android and iOS projects to open the Reference Manager. Untick the C# library and tick the Visual Basic .NET library instead. Do this for both iOS and Android. Finally, delete the C# project. You can now develop your Xamarin project in VB.NET by adding more .vb files as necessary.
Unfortunately, VB.NET has a few limitations in regards to Xamarin:
You can't write custom renderers or dependency service implementations in VB.NET. These must be written in C# or F#.
You can't include XAML pages in VB.NET projects. You'll have to use a workaround that involves including XAML pages in a seperate, C#-based, portable class library, referencing it, and populating the XAML models with VB.NET through databinding. Alternatively, this may be of help for using XAML with VB.NET.
More info can be found at Microsoft's website.
I know this question is three years old, and that lots of time has passed since that school project, but I hope this answer was helpful to you regardless, and / or that it will be helpful to others who have the same or a similar question. To anyone about to write Xamarin apps in VB.NET or who is currently doing so, I wish you the best of luck!

How to add Linq to SQL class

I can't find Linq to SQL class when I tried in my VS2017.
From within a C# application, on the Project menu, click Add New Item, then there is not 'Linq to SQL'.
On Visual C# Items, it only shows
Classes
Class for U-SQL
Forms Blank Content Page Xaml
... and the last item is
WCF Workflow Service.
There is any Setting error on me?
Would you tell me any hint?
First step - Missing LINQ to SQL Classes (DBML designer) in Visual Studio 2017 RC
Second step - Go to project properties -> Under Application tab select Target Framework to .NET 4.0 or higher and save.
It resolved my issue, hope it resolves yours too.

Cant add using Telerik.UI.Xaml.Controls.Grid namespace

I am trying to use the Telerik RadDataGrid in my project. For starting off I have just copied the code given the "Telerik Controls Example" app. But when I try adding the namespace "using Telerik.UI.Xaml.Controls.Grid" I get an error
"The name "RadDataGrid" does not exist in the namespace "using:Telerik.UI.Xaml.Controls.Grid".
I have been able to use the RadCustomHubTile easily till now but RadDataGrid is giving me problems. RadDataGrid does not appear in the toolbox also.
I have added Rad Controls for Windows 8 in the reference section.
I am using C#, xaml, visual studio 2012 and trying to build a windows 8 app.
Any help would be appreciated.
Thanx :)
For those who do not know the answer here it is.
Just add this namespace: xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
And in no time you can be using <telerik:RadGridView />!!!!