![]() Right click on Module1 and select “Rename”. Now third party add-ons like ReSharper offer a convenient context menu for locating the current file in the Solution Explorer on demand, but we can pull it off quickly in Visual Studio via a simple macro bound to a keyboard shortcut. So getting this behavior on demand is the way to go. However, the constant jumping around in Solution Explorer is distracting and be a hindrance when you don’t want to lose your current location in the explorer. Check “Track active item in Solution Explorer”. ![]() Tools > Options > Projects and Solutions > General. You can set the solution explorer to always stay in sync with this simple setting: Using linked files can be handy when you want to share code or resources between multiple projects.Visual Studio doesn’t offer an easy way to locate the current file you’re editing in the Solution Explorer on demand. In this example, I also set the CopyToOutputDirectory to PreserveNewest, so that the file will be copied to the output directory when the project is built or published. If you change this file name, it will also change the filename as it's displayed in Visual Studio's Solution Explorer.įor content files like JSON configuration files, you would use the element, for example: Include gives the relative path to the file from the project folder, and the Link property tells MSBuild to add the file as a link, plus the name that should be used for it. cs file, you would use the element, nested in an : The exact code required depends on the type of file you're trying to link and the type of MSBuild action required. csproj file yourself and add the necessary items by hand. Visual Studio shows linked items with a slightly different icon, as you can see below where SharedSettings.json is a linked file and appsettings.json is a normally added file:Īs you'd expect for ASP.NET Core projects, you don't need Visual Studio to get this behaviour. ![]() That way, if you modify the original file you'll immediately see the changes in your project. Instead of copying the file into the project directory, Visual Studio will create a link to the original. Instead, click the little dropdown arrow next to the Add button and select Add as Link. To add a file as a link, right click and choose Add > Existing Item… as before, but this time, don't click the Add button. ![]() Adding files from outside the project by linking Sometimes this is the behaviour you want, but often you want the original file to remain where it is and for the project to just point to it, not to create a copy. Visual Studio will spot that the file is outside the project directory and will copy it in. ![]() You're then presented with a file picker dialog, so you can navigate to the file, and choose Add. You can easily do this from Visual Studio by right clicking the project you want to include it in, and selecting Add > Existing Item… Sometimes, you might want to include an existing item in your ASP.NET Core apps that lives outside the project directory. Adding files from outside the project by copying I suspect this feature may have slipped under the radar for many people due to the slightly obscure UI hints you need to pick up on in Visual Studio. This post is just a quick tip that I found myself using recently - including files in a project that are outside the project directory. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |