I am currently trying to add a VB file inside a C# project, but I am only able to add C# files. Is there a way for me to be able to add more language templates like what is shown below?
This picture below is an example of what I have been able to do in an old project which is to be able to add both VB and C# files into one project.
Update: I am redeveloping an ASP.NET 2.0 site to the newest version with the new bootstrap framework. I didn't realize the old project was using mostly VB until I started the redevelopment in C#. I noticed that the old project is also using some C#. I am trying to see if I can have those two languages inside a new ASP.NET project or not by adding VB files. If not, I'll just make a VB project and convert all of the C# code to it.
When you open the "Add new file" dialog inside a project, it is filtered by the current project type you're working on. E.g. you cannot add a *.vb file to a C# project type, without hacking it somehow.
The GUID within the *.csproj file defines the current project type. This site contains a set of known GUIDs, it is somewhat outdated since it's from 2008.
As I said in a comment, the reason you have been able to mix-in both VB and C# code within the web project, is by using CodeFile attribute, rather than the CodeBehind attribute. The latter will compile all the source files within the project into an assembly with the same name. This will be the file you are uplading to your webserver along with the .aspx files.
Sample file structure:
bin/MyApp.MyProject.dll
Index.aspx
The CodeFile variant, which compiles the source on the fly will need all the files in the same directory, or in the directory specified within the attribute, for this example it will reside within the same directory. This will also allow you to change the code at the web server, and not having to download the code to your development environment. (This is NOT recommended, as you wave goodbye to any version control and other useful tools.)
Sample file structure:
Index.aspx
Index.aspx.cs
My advice would be to decide whether or not to continue developing in VB, or switch to C#. Containing your codebase to one language is preferrable. And if you decide to refactor the whole solution, why not give ASP.NET MVC a go? :-)
Actually there used to be, not sure if it's still available, to put a VB file in a C# project. You would have needed to add a text file type but name it with a .vb extension. Then place it in a folder. Then in the app or web config, you needed to add some config to tell the runtime where to find the vb files and to use VB compiler to compile the code.
It worked but was clunky and not recommended. Again, not sure if it's available anymore.
Personally, if you have VB code, use a vb2cs converter like this one to begin converting it over. They are not perfect but it's at least a good start in most cases.
Related
I'm working with the VS2008 version of the source code for AjaxControlToolkit. There are some changes I need to make to the javascript base files (MicrosoftAjaxWebForms.js, etc...) but I can't seem to find where they are generated from.
I know what changes I need to make, but I can't find which files it is that the toolkit is compiling from.
Since we need to make some changes to the functionality of the toolkit, and also because we're working with VS2008, we can't use the NuGet version of the toolkit. The project is in ASP.NET 3.5 framework.
There are certain scripts that are a part of the ASP.NET AJAX framework. I'm not sure how exactly you can go about changing those, as they are embedded in the framework. I'm not sure if MS released the System.Web.Extensions code base, but that's where the script comes from. Internally, the ScriptManager control renders this script to the client.
This took quite a bit of searching, but eventually reading through the build steps in the .csproj file I found where I needed to look. The relevant .js files are located in the Client\ScriptOutput\Embed folder of the source zip. These contain most of the necessary JS but note that the build process of the Ajax Control Toolkit will add extra locale-specific resources onto the end of these files.
One of our clients has installed our web application into production.
We need to do a very quick patch to one of the aspx controls. I tried dropping the ascx and ascx.cs source files into the dir and unsurprisingly I got this error:
Exception type - HttpParseException - The base class includes the field 'foobar', but its type (UserControls_Controls_FOO) is not compatible with the type of control (ASP.usercontrols_controls_foo_ascx).
Yes, this approach is never a good idea, but is there anything I can do to the control to get it to run in the site instead of the version compiled into the DLL?
Doing a fresh install is not an option at this point.
no , you need to get it into compiled DLL and fresh deploy only then you can see the patch working
If you changed only ascx file you must update only it.
But if you updated ascx.cs you must Publish project and replace old bin directory with new one.
Also you can transform site to set of dynamically compiled pages, but it is hardcore old way and bad idea nowadays.
Several years before I started working at this job another developer who is no longer here wrote an application in classic ASP using HTML, vbscript and javascript. This is fine but the problem is that 2 pages were written in C# with an HTML file and a code behind file. There was no solution files for these two pages. They may have been originally created in Visual Studio but they don't exist in it now.
That is important because there is a lot of things that Visual Studio just does for you without even thinking.
My problem is that in these two C# pages I need to get them to reference a DLL. This is a simple task when using Visual Studio. You just add a reference to the project and life is good. But outside of VS nothing seems to work.
I tried putting the dll in the same folder as the pages and then I tried the following:
Using myDLL;
myDLL dll = new myDLL();
myDLL dll = myDLL();
I found some code online that said to create an internal static class and use [DLLImport()] but that didn't work either. It couldn't find the dll or the Entry Point for the dll. I am currently researching how to create an entry point, just in case this is the method to make everything work.
Outside of having to rewrite these pages in vbscript (which I don't have the time to do) I am at a loss.
Has anyone ran into this problem before? Is there something that I can put in the web.Config? Or is this just impossible and I am hosed.
BTW this is all running under the 2.0 .net framework.
If you drop the DLL you want the code to reference into the bin folder of the website, then open the web.config and locate the following section configuration -> system.web -> compilation -> assemblies.
You need to add the display name of the assembly to that list - so that the compiler will reference that assembly during it's late-bound build process.
Now you should be able to use the stuff that's in it on those pages.
If you don't the know the display name of the assembly (typically yourassembly, version=*.*.*.*, Culture=neutral, PublicKeyToken=null for culture-invariant, non-strong-named assemblies) you can open it in a tool like ILSpy (there are others, it's just become my favourite) and it tells you when you select it in it's UI:
sorry for the poor highlighting - jerky hand following far too much coffee
If all the code in that assembly is in a single namespace, also, you can also add a default using to all the .cs or .aspx code in the project by adding that namespace to configuration -> system.web -> pages -> namespaces - making it simpler to use that code in the pages.
I created a VS Solution/Project for my app. I compiled and published it to the web server. When I published it I had it copy all project files.
I ran it and it crashed because it could not find my dll.
I tried adding the lines that Andras mentioned above and it seemed like it was getting me closer but it only changed the errors I was getting.
Then I went into IIS on the web server. I expanded the folder listing under Web Site. I right clicked on the folder that contained my app and made that folder into an application folder.
After I did that everything just worked. So then I thought I would see what happened if I backed out all of the additional code I added to my C# app and the Web.Config file. It still worked. All I needed to do was to make the folder an application folder in IIS and put a Using statement in my C# app and life is wonderful again.
Thanks for all the comments and suggestion. Andras thanks for the link to ILSpy. That is a cool little tool.
Take care,
Robert
I agree with Jon, it sounds like you should try creating a new project for these files. It's always better to leave code better off than you found it. If a new project is not an option for some reason, you should indicate this in your question.
I have a simple C# project which loads external C# files at startup to be used as scripts. Unfortunately when editing any of these 'non-project' files in Visual Studio I only get the most basic of syntax highlighting, since classes and types within the project are not known in the context of this external file.
Without adding the files to my project (defeating the purpose of them being external scripts), is there any way I can define an external interface or somehow otherwise convince Visual Studio (2008) to parse the code within these files in the context of the classes in the project?
A couple of clarifications (with thanks to the early answerers)
People should be able to edit these scripts without access to my source code
People shouldn't have to set up an entire Visual Studio project to edit one source file that's likely to contain less that 10 lines of actual code.
You will always need a reference to these classes. Maybe you can add these files as a link to the project or to a new project with a reference.
Visualstudio needs some informations to accomplish that.
I would think about the Bridge Pattern and you need to add the class body in the same file
http://en.wikipedia.org/wiki/Bridge_pattern
or using mock objects- you can easily use them to provide syntax highlighting without sharing your code (the same here - all in one file):
http://en.wikipedia.org/wiki/Mock_object
You can separate the script and the assiting classes if you would allow having a project file.
I'm currently working on an application that will generate actual .cs and .xaml code files and add them to a project. I've managed to do this by manually editing an existing .csproj file and thats working well.
However I would like to be able to create the project files from my application as well, to cut out the extra step of creating the project first then running the application after.
Does anyone know how to create a C# project (class library, or WPF Application) from an application? I've looked into DTE, but I've hit a wall
I can't give a complete answer, but maybe I can point you in the right direction.
One avenue to explore in your own searching is MSBuild. C# and VB.net project files follow the msbuild format, and so the first step in building a valid project file is building a valid msbuild file.
Also, it sounds like you're doing something a little different, but have you looked at the T4 system for code generation?