I'm completely new to ASP.NET core, and currently going through a tutorial on Udemy. The instructor is using visual studio code and I've chosen to go with visual studio.
I created a ASP.NET Core Web API project, and now I'm trying to add a new class so i can start creating the first entity, However when i create the C# class and give it a name the name within the class file doesn't change, it just remains as "class1".
Does anyone know how i can resolve this?
See screenshot below:
The class name here is supposed to be "AppUser" not "class1". I'm so confused this has never happened in any of my .Net Framework projects.
Typically when you create a new Class file, you'd go through the create dialog which allows you to set the file name which will also be the name of the class. "Class1" is the generic default file name. You can also refactor (Right click > Rename or default key binding F2 with the caret on the class name definition) which Visual Studio will ask if you also want to change the file name to match.
There is no change from net framework to net core concerning how you name a class.
Just go to the file and rename it, then go to the code and rename if VS wont do it automatically.
It seems much more like a VS bug. Close and open it again in case the problem persist.
Adding Additional Activity .cs and Layout axml Using Visual Studio 2015.
I'm very new to Xamarin and Android development, but have been a developer for a few years using VB and now C#. I have a simple app on Android 4.2 that is getting more complicated as I go along. The simple matter us that I want to add an additional GpsAction.cs and corresponding Gps.axml layout to the project. It seems impossible to find the right combination syntax to achive this. I have a mainActivity with main.axml. In VS 2015 it's very simple to add new but I keep getting "resource.id does not contain a definition for" I would really appreciate your help with this
namespace AddCam
{
[Activity(Label = "GpsActivity")]
public class GpsActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.GpsLayout);
string c = FindViewById<TextView>(**Resource.Id.textView1**).Text;
// Create your application here
}
}
For people who are still facing this issue, the default Build Action of the layout file would be set to TransformFile. Select the layout, go to the Layout Properties, and in the properties pane, Select AndroidResource as your Build Action. Clean build your project and it should work.
I changed the text field "id" from "#+id/imageView1" to "1", saved, rebuilt and changed it back to "#+id/imageView1", it fixed it. I would like to add, this whole problem came from
Adding a new activity and layout.
Using preexisting code from another app that I had.
Copying and pasting code from the original app to the new Activity
and Layout.
All fairly common stuff, the real problem seemed always to be adding any new Activities and Layouts to a main Activity. It can get very convoluted and with no (known to me) logical way to run down a problem with Xamarin. Don't get me wrong compared to 10 years ago (the last mobile app I tried to write) Xamarin is heaven. Good coding folks, now if I can only figure out why Keyword "this" is error-ring on the added Activity.cs
Just add namespace like that Android.Resource.Id - it's resolve for me
What did work for me (Visual Studio 2017, opening an old Xamarin project):
Delete obj and bin folders, build.
If errors, restart Visual Studio (I know the pain).
Build again
Now the Resource will be visible (of course, if you defined it correctly).
The best solution I have found is to build solution.
Choose Build solution from Build menu (or Ctrl+Shift+B).
This action will resolve the issue.
You Should add set value forandroid:id="#+id/button1" in axml of app, then rebuild the project and try again.
like thisButton button = (Button)FindViewById(Resource.Id.button1); .
Check if you are missing these namespaces in your layout file -
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
(VS 2019) I did the previous solutions and nothing, I had the same problem and the solution for me was to remove '&' from the text of TextView, I was trying to Set the text to "text&text" even &&(I though it was like mnemonics as in WindowsForms) didn't work so I had to remove it and it fixed.
Cleared Main.axml page and Reset and it is working.
My problem was I was trying to debug Xamarin Android project (native) using Xamarin Live Player, connecting using USB cable and selecting my device for debugging solved the problem
Make sure your axml is well formed and rebuild the solution it should work, if you continue facing the same issue then remove axml and add it again then build the solution.
In Visual Studio 2019 when you add a new Android Layout to the Project it is added as .xml file. I already had some created earlier layouts in Resources/layout folder with extension .axml (not .xml) and for me changing the extension .xml -> .axml worked.
I understand that this issue is very old, but I've run into it as well in Visual Studio 2019, and have found a solution.
The issue occurs, for me, when adding an element to the layout and then attempting to add code. The issue appears to be related to the way the project is built.
Add the element to your layout, then build your project before adding any additional code. Apparently Resource.Id does not update with additional members until it's built, and attempting to refer to the new member in the code before Resource.Id recognizes it prevents the project from being built.
Like Maniacz said, in VS 2019 I just had to change the XML to axml extensión to the layout in layout folder under resources
For anyone else looking for an answer despite running clean/build/rebuild which didn't work for me:
I had freshly installed a number of tools for xamarin development in VS. Though a build/rebuild may have actually worked, in my case I believe what also fixed it was closing and re-opening VS. I'm pretty sure I had a few issues, primarily stemming from newly installed tools (android SDKs in my case) requiring VS to be restarted. If you're working on a project already having installed the tools you need, try as others have said - build/rebuild.
I had to modify Build Action for my layout file and re set the original Build Action as it was previously set. This made my visual studio to regenerate the resource ids in Resource.designer.cs file.
Step #1:
Go to properties of the layout file that is missing its ids and click the Build Action DropDown.
Step #2:
Select something from the dropdown other than AndroidResource.
Step #3:
Reselect AndroidResource from that Build Action.
Now, you will have your Resource.designer.cs file regenerated and it will have the reference ids to your controls in the layout file.
Check the Resource.Designer class file. There will be a class like public partial class Id. There the integer IDs of the controls are written. Use them instead of Resource.Id
I'm working a bit on CodeGeneration and Visual Studio integration- -> And I need some help...
Since I`m working on it, most of the time I used Visual Studios vsix-projects and ProjectTemplates to create new ProjectTemplates as Visual Studio Extension.
But know I'm wondering if it's possible to create a "Add new Project" Dialog without using a ProjectTemplates in the vsix. Cause I don't want to a have a"standard" project in my solution which is automatically created from the template. I just want to call a Wizard which simply implements the IWizard interface and does all the solution creation process.
So, is there a possibility to create a "New Project" entry without having a ProjectTemplate ?
Hope you can guess what I'm trying to say ;-)
Thanks for your help :-)
[Edit-----------------------------------------------------------------------------------------------------------------]
To make my explanation easier to understand.. Sorry guys...
This is the normal ProjectTemplate process with a wizard (IWizard)
What I'm trying to do is something like this
If you are willing to create blank solutions try this -
New Project >> Other Project Types >> Visual Studio Solutions >> Blank Solution
The solution will be blank -
I know this sounds stupid, But i never had to create an interface file in visual studio as worked in support projects mostly.I thought it must have a template but cant see one.
Create an example and use the option in the file menu option to create as a template.
Look at http://msdn.microsoft.com/en-us/library/ms247121.aspx for more options.
I am trying to generate a Visual Studio 2010 solution and add VS 2010 projects from custom templates!
My requirement:
1. Generate a VisualStudio Solution 2010, Save it to a folder, add VisualSTudio Project from my own templates (I have 3 different templates: ClassLibrary,WinForms ,WCFService)
My issue:
I implemented something that is working half a way!
Solution is created correctly but the content of the ".sln" file is very poor! No project reference is added >
In the root folder, it creates a Solution also for the C# Project, which I do not want. I want only the MainSolution file. (In my case "TestSolution.sln"). How can I stop creating a solutionfile for each project created?
Below the source code I use:
//for The solution:
//adding a project
Am I using the wrong interfaces?
Why the vs2010Solution.AddFromTemplate(..) returns null after the call, but no exception is thrown? Also the Project is created correctly in the folderstructure! But at runtime I can't check the list of projects "vs2010Solution.Projects" as it is null! (After correctly adding a project). I need the Project added because I need to add some references programmatically, which I try to do in the next line, but it doesn't work because vs2010Project is null).
So I am trying to wrap the VisualStudio 2010 automation model, to create a solution and add projects! But is not really working! Do I need to cast EnvDTE.Project to "VSLangProj.Project" at some point? I want to create a clean wrapper for VS2010, after that one for VS 2012!
Any help is much appreciated.
See the several articles of the section "Articles about automating project creation" on my web site:
http://www.visualstudioextensibility.com/articles/add-ins/
They explain why AddFromTemplate method returns null, how to create a solution, a project, a project inside a solution folder, a project item, etc.