Include a file in a Xamarin project - visual-studio

Here I decided to train on Xamarin. I am currently a tutorial. My problem is that when I try to add a ContentPage I only have the class file that is included in the project. If I display all the files of the project I see my view but can not include it in the project. I put you a screenshot below.
So if anyone has an idea of ​​where the problem may come from or a method to import my file I am a taker.
Thank you in advance.

Stop your project before trying to include something on it with the Visual Studio interface.
Otherwise edit the .csproj manually, which is located on the root folder of your project and put the path to your new file manually like it's made on the others. You won't see the .csproj file with Visual Studio so use another editor instead.
See this link for more details about importing it manually

Don't include .xaml and .xaml.cs files manually/separately, use the Add new class context menu instead (right click on Views folder) and select the kind of class you're interested in. The .csproj will automatically link the 2 created files like this :
<Compile Include="Views\MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
Your .csproj seems to be confused now, I suggest you don't try to edit it manually (for now), delete all CounterPage.* and start over.

Related

Is it possible to configure a csproj file to allow any project item type?

I'm working on a unique project in that I would like to be able to have CSHTML Razor Views, Windows Forms, and various other "non project type crossing" project item templates in one single project in visual studio.
Is there a way I can override the project type so that it compiles as a Windows Form's project but still allows me to add CSHTML files and other template types to it?
When you edit the .csproj using notepad or an xml editor you'll find that <ProjectTypeGuids> element.
You can then edit it to have an entry like below
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Note: these are Guids from a portable class library project. You need to find correct ProjectTypeGuids for your requirements and add it.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/d9d05cdc-96a1-4044-95d8-a4f8885a660a/what-is-the-significance-of-projecttypeguids-tag-in-the-visual-studio-project-file?forum=vsx

Is there an extension to link a file to another like the .designer files

Is there an extension to easily link a file to another in a VS project? The same way a designer file is linked to another file.
I know i can open include the file in the project then open the project in notepad and change
the include element to depend on another file like
<None Include="Features\ContactTestData.json">
<DependentUpon>ContactInfo.feature</DependentUpon>
</None>
but is there a way to do this through the UI?
It sounds as if partial classes may solve your issue. Which is how the form designers work.
It allows you to have multiple class files with the same name in the same namespace accessible as the same class.

How do I disconnect code generated by a T4 template from that template?

When I 'run' a T4 template, the class files it generates for me all appear under the template. I cannot remove the template from the project without the files going away too. I also can't copy the files out from 'under' the template into the project root because the are already in the project root. How can I emancipate these files from the template that created them?
Get creative:
Right click and open containing folder.
Drag-and-drop the generated file to another location in the solution.
Delete the original template and file from Visual Studio.
Presto.
If you want to do one-time code-generation with T4 then I would suggest using T4 scaffolding. This tool was originally created to support the generation of views, controllers etc. in MVC3 but you can use it on pretty much anything.

ASP.NET MVC3 project does not always publish all views/content

This is crazy, but I can't seem to get all my views/content/scripts published when I publish the site. This seems to happen, I believe, when the view or content is not directly referenced by my project, but used by another assembly in my project. So I might have:
ExternalAssembly.dll referenced (it gets published)
I'll need ExternalLogin.cshtml in my main project, under my views folder
ExternalLogin.cshtml doesn't get published
Right now I have a script that copies everything in the Views folder and dumps it to where I want it deployed, but VS should do this for me. What am I doing wrong?
When you click on one if these files what is the build action for it on the properties? Content....or? Set to content.
So your views files are in another project or folder outside your current project? Normally the files have to exist in the web site project, in it's views folder, not externally, and the build action should be set to Content and not to copy to the output folder. But there are some workarounds:
Duplicate them in to your site views folder and make sure they are marked content (as stated in another answer). One thing to note though is that you can add them as "Linked Files" in visual studio which actually allows them to exist in two places in the hierarchy without having to exist in two places on disk: http://support.microsoft.com/kb/306234
If you have control over the external library, you can compile them in as embedded resources or use Razor Generator or something similar and use a custom view engine to return them: How can I make ASP.NET MVC 3 use views (aspx, ascx) files from an external assembly in my website?
Manually put the copies in the .csproj build XML using the Copy task: http://msdn.microsoft.com/en-us/library/3e54c37h.aspx (Note that this will make it work in visual studio doing essentially what you are doing now, as it will then be part of the Visual Studio build if you add it to the AfterBuild target or something)

How do you make a t4 template installable in visual studio?

I have written a couple of t4 templates for EF4, I want to get other developers to use them, so id like to make them installable in VS so that people cna jsut add them to their projects.
I have no idea how to do this. Any idea about where i should start reading? Idid a quick google and had no luck.
Thanks.
An alternative is to create a VS item template.
There is an export template wizard accessed vie the File/ExportTemplate menu.
After you've exported a T4 template, you'll probably want to manually edit the resultign item, as it doesn't handle the generated file well by default.
You'll have your template from the wizard as a zip file.
Unzip this and remove the generated file.
Then edit the Foo.vstemplate file and remove the line referencing the generated file.
Finally zip the files up again.
Your colleagues can just drop this zip file into their user templates directory:
C:\Users\\Documents\Visual Studio 2010\Templates\ItemTemplates
For external sharing, your best bet is probably to create a nuget package.
Have a look at this link:
http://haacked.com/archive/2011/01/12/uploading-packages-to-the-nuget-gallery.aspx

Resources