c# compilation error "missing static Main" in .net6 - c#

(beginner)
I'm trying to understand LinkedList and I have one working in .net5 but when I am trying to move it to .net6 it gives "missing static Main" error. Do I need to use the template showed in the link below or move classes to other file OR there is different work around?
At what point do I have to include old template? Is it at creating new class? Is empty template only used to create very basic code and nothing more?
I know that using template in link solves the problem but I would like to get wider understanding.
https://learn.microsoft.com/en-us/dotnet/core/tutorials/top-level-templates

Related

How to compile Item Template Project for Form with substitute parameters

I am trying to make an ItemTemplate for a Form. I create a "c# Item Tamplate"-Project, make my Form, and create my Template by Building the project. That works fine.
Now I want to add Templateparameters but as soon as I do, the project wont compile any more. It throws many different exceptions because the code is no longer valid. How can I solve this problem?
Here is what I tried so far:
Replacing every occurrence of my Classname with $safeitemname$. This, as I already said, throws exception because now the code is invalid and the project can not be built.
Creating CustomParameters in my .vstemplate to change a valid class name to my desired parameter (Classname -> $safeitemname$). This does nothing, even though I set "Replaceparameters="True"".
Ignoring the compiler warnings and implementing the project in my .vsix project anyway. This does nothing either, because the .zip for my template still can not be.
Setting DependentUpon of my Classname.Designer.cs to my Classname.cs. This does nothing either.
Trying a simple ItemTemplate with one class that's divided in two partial classes that have one Property each. Same thing as with the Form. It can no longer be build.
As Reza Aghaei suggested in his comment, the problem was, that I didn't set the build action for the files in my project to 'None'.

Add files to existing project programatically using C#

I am currently developing a solution that has two projects on it: one is some kind of API where I put all the functions that I want to use in the second.
So, at some point in the project, I need to create a file programatically. This is ok, but I need to include that file in my second project to use the functions from the first projects! Any idea on how to do this?
I have tried the EnvDTE but I think it only works if you are creating a new solution and a new project.
Really need help on this! Thanks in advance! :)
Are you literally trying to recompile the second project after creating these files or is this all happening at runtime?
To me it sounds like what you're trying to do is really not create a file but to emit a class in memory during runtime to make new functions available to the second executable. You should check out Reflection.Emit. That is how you define classes, even assemblies, that didn't exist when you started running the program. Check out MSDN and this code project article.

The namespace already contains a definition in wsdl-generated file

I'm trying to integrate reporting services in an C# application, but when I'm trying to compile it I'm getting a bunch of 'already contains' errors, just like those two:
error CS0101: The namespace 'Microsoft.SqlServer.ReportingServices2005' already contains a definition for 'ListSecureMethodsCompletedEventHandler'
error CS0101: The namespace 'Microsoft.SqlServer.ReportingServices2005' already contains a definition for 'GetRenderResourceCompletedEventHandler'
They all come from ReportingServices2005.cs file, which was generated using wsdl and which I included in the project. What am I doing wrong here?
I probably should also mention that I'm using ReportingService2010.cs and ReportExecution.cs.
Well, that was easy enough. It was my first time using ReportingServices in C# and I misread the documentation. I thought both ReportingService2005 and 2010 are needed. After excluding ReportingService2005 and changing a few things everything worked.

How to generate solutions with a template?

I'm having a bit of trouble here.
I want to be able to generate a C# project (and solution) (let's say a C# Console Application) using a template similar to the ones VS2010 uses.
Basically I want to have a method GenerateConsoleApplication which does just that. But since I will need to generate several of these, I want to use a template to populate the Main method of the program.cs class which will be generated alongside the .csproj and app.xml files.
public void GenerateConsoleApplication()
{
var projectName = "MyConsoleApplication";
var projectLocation = "C:\temp";
// what goes here so that it creates a solution Visual Studio that I could use ?
}
I looked up the project template used by VS2010 to generate a C# Console Application and am thinking I could modify it to suit my needs. But I have no idea what I would need to write (code wise) to use the said template and generate all the files of the new solution.
Does anyone know how to do it ? Or if it is even possible ?
I know I could just write the csproj file and the others but I think a template would allow changes more easily.
Just found what I'll need to do.
The problem boils down to the parsing of the templates files.
Once I get the parser, then I can replace the tags with the appropriate values. I wanted to use Visual Studio's parser to do that, and slightly modify the templates it already uses, but it's not possible.
So one has to write its own parser and use it to generate the files.
Then Regex can be use to replace the tags of the template file with the Regex.Replace(String, String, MatchEvaluator) method.

App_Code class not auto completing and cant use it in rest of project

I am creating a site and thought I would do it correctly so I created an App_Code directory and created a class in there.
when im editing the class file the auto complete no longer works, which I can live with, however, no matter what I do in my main site I cant access or reference the class file.
ive tried
putting a using statement at the top of the file, but it just throws an error
creating an instance of the class in the code but that throws and error
can someone let me know where im going wrong
thanks
Make sure your class is public
EDIT: And as #Oded has commented, remove the Namespace
App_Code is used for Website projects and not for Web Application projects. It will not work as expected for web application projects. MSDN
Is your project a website or web application?

Categories