Visual Studio Code default namespace - visual-studio-code

When I create a file within a project in Visual Studio Code, it generates namespace folder_name automatically. How would I get all files I create within that project to generate namespace solution_name.folder_name automatically?
I tried setting the <RootNamespace> in the csproj file and that didn't work.
Thanks.

you can use [Add folder to workspace]

Related

Trying to set my configuration file as a defult configuration file for Visual Studio Code Extension

Is there any way using which we can force Visual Studio Code Marketplace extension to use our own configuration file instead of their own default .config file upon installation?
I really want to use my own configuration file for a particular something.

Is there a way to change vs code settings based on current open directory?

I'm wondering if there is a way to change my theme based on folder name in Visual Studio Code. I'm constantly mix up together my front-end and back-end projects. Thanks for replies :D
Inside the folder add folder .vscode and add settings.json inside that folder with the following code:
{
"workbench.colorTheme": "Kimbie Dark"
}

how to use code from github with visual studio?

I need the following code https://github.com/reo7sp/tgbot-cpp
I downloaded the zip file, now I want to include tgbot.h.
I tried to paste the tgbot folder (/include/tgbot) in the project folder but to no use.
Any solutions?
This problem is not related to GitHub. You can open the project folder with Visual Studio. I think no need to paste tgbot folder.
check the solution explorer
If you want to open separetly include/tbbot folder then just right click on the folder and select open with visual studio.

Specifying additional source folders in Visual Studio Code

I'm porting two AS3 projects to TS using Visual Studio Code.
The second project uses code from the first project's folders.
I wonder if it is possible to specify additional source folders outside the main source folder in Visual Studio Code, like in the old good FlashBuilder.
For example:
Main source folder: "src"
Additional folders: ["../previous_project/src", "../previous_project/libs"]
This way I can use or extend classes from the external projects like if they were saved in the main source folder.
Investigating a bit I've found that the 'Insiders' version of Visual Studio Code have something called 'multi-root workspaces'. I made some experiment with it, but I must be doing something wrong: When compiling, I get:
"error TS6059: File is not under 'rootDir'.
'rootDir' is expected to contain all source files."
So, how do I specify additional source folders in Visual Studio Code?
After playing a bit more with workspaces, it seems that commeting out "rootDir" in tsconfig.json removes 'error TS6059'. Now I can compile with no issues.
It would be good to see a correct example of multi-root workspaces, though.

Is there a way to use shared projects (shproj) in Visual Studio Code?

Hi,
Shared project seemed like a good idea to share code between .NET Core 2.0 web project and .NET 4.7 WinForms project.
I have bunch of extensions inside as well as web api client code which is used by both projects.
Everything works well in Visual Studio 2017.
However, on the road I use MacBook computer with Visual Studio Code which does not recognise shproj in any way. I also tried Insider version with new multiple workspace, but that also seem to work only with actual projects (csproj).
I know there is Visual Studio for Mac, but it is huge and far exceeds my on-the-road needs, so I would like to avoid it.
So, my question is - is there a way to utilize Visual Studio Code with projects that use shared projects (shproj)?
I would like to run/debug such projects in VSCode.
If not, does it make sense to create feature request somewhere? I mean, shared projects were designed for cross-platform code sharing and VSCode is brilliant cross-platform editor so it makes sense.
Or is this not part of VSCode at all, but some extension (like OmniSharp)?
Thanks,
Mario
At least now (2021) it seems to work fine.
TLDR; Create a new project with Visual Studio (2019) and add a "Shared Project" to that Project/Solution. Then open the project folder in Visual Studio Code and add the Shared Project folder to Workspace. In VS Code add a new Class to the Shared Project and adjust the *.projitems file to include the new class in the compile process. Run the project in both VS Code and VS to verify everything works as expected.
Following are the steps that I used. It looks like a lot, but it should only take about 10 minutes to setup this basic sample.
Open Visual Studio (2019)
Create a new "Console App (.NET Core)", give it a name and a location and select "Place solution and project in the same directory".
After creating the project you should have a new solution in "Solution Explorer" containing the new Console Application project.
Right-Click on the solution and select "Add" > "New Project..."
Select and add a new "Shared Project"
Add a new class to your Shared Project. In "Solution Explorer" right-click the shared project and select "Add" > "New Item..." and select the "Class" template.
In your "Console Application" add a reference to your Shared Project by right-clicking on your Console Application project, then select "Add" > "Shared Project Reference..." and select the listed shared project (*.shproj)
Use the new class of the Shared Project in the Console Application project
Run the Console Application to check if it builds and uses the shared class successfully.
Close Visual Studio (2019)
Open Visual Studio Code
Select "File" > "Open Folder" and select the folder where the Console Application is placed.
Note: If VS Code shows a message "Required assets to build and ... are missing" then select "Yes".
Select "File" > "Add Folder to Workspace..." and select the folder where the Shared Project is located.
Select "File" > "Save Workspace As..." and save the file to the project folder of the Console Application.
Open a new integrated Terminal in VS Code (in Menu "Terminal" > "New Terminal") and make sure that the current working directory is the folder of the Console Application. Then type "dotnet clean && dotnet run" to clean, build and run the solution.
Assuming we now want to add a new Class to the Shared Project from Visual Studio Code, we have to do some extra work, that normally Visual Studio (2019) would do for us when adding a new Class.
In VS Code right-click the folder where your shared class is located and add a new File. Give it a name with .cs extension and add the according code to the file to make it a valid class file.
Open the *.projitems file and find the part where your first class file has been added already. It should look like this:
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)SharedClass1.cs" />
</ItemGroup>
Now add the new class file to this ItemGroup section like this
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)SharedClass1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SharedClass2.cs" />
</ItemGroup>
Use the new class in the Console Application, save all files and type "dotnet run" in the integrated Terminal.
Check if everything builds and runs as expected.
If you notice that it builds successfully, but VS Code shows some error like "The type or namespace name 'Class2' does not exist in the namespace 'SharedProject1'", then restart VS Code. After restart it should be able to detect everything as expected.
Close VS Code and Open VS (2019) by double-clicking the *.sln file.
Build and Run the project to verify that all changes are compatible with VS (2019).