I have a .NET Core 3 project in Visual Studio 2019. When I copy and paste a file, through Windows Explorer, into the project folder, Visual Studio automatically includes the file into my project, which I do not want to happen. Is there a setting to disable this feature?
Starting from VS 2017 project format in .NET has changed. You need to add <PropertyGroup> tag at the top of your .csproj file:
<PropertyGroup>
<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>
Here is the complete answer to your question:
In Visual Studio, why are all files automatically part of my C# project?
Well, you can modify the known project file (.csproj for c# project), by customize the items include path that satisfied your include files specifically.
For more details, you can check these out:
https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-well-known-item-metadata?view=vs-2015&redirectedfrom=MSDN
Understanding a csproj assembly reference
Including content files in .csproj that are outside the project cone
Enjoy and deploy with confidence!
Related
When i pulled code from team explorer in visual studio code . Rzc generate exited code 1 error occured. I am unable to build project.how to solve this error?
Target framework .net core 3.1
Open the Project in visual studio-> check in views folder for any files having X - red color symbol then remove that file from visual studio.
Previously you deleted the files from folder - that is the issue.
ie, Razor Engine trying to render those files, but the engine could not find the physical location of that file, that is the problem. Always delete the unwanted files using the visual studio or any project editor. That is the best practice.
I solved rzc generate exited with code 1 microsoft.net.sdk.razor.codegeneration.targets
by undoing the changes that deleted a project from the folder in file explorer instead of visual studio.
In your Project.csproj, you should have a piece of XML code like this:
<ItemGroup>
<Folder Include="Controllers\" />
<Folder Include="Views\Home\" />
<Folder Include="Views\Shared\" />
</ItemGroup>
It depends on your folder structure.
In case you are using Windows 7 and getting the 'rzc generate exited with code -2147450750' while debugging a .NET Core app, try installing the standalone package: Microsoft Update Catalog - KB4457144.
I had the exact same error message (apart from the directories) on Windows 7 with a newer VC++ distribution already present.
The package contains the KB2533623 that we want. Details of KB4457144: September 11, 2018—KB4457144 (Monthly Rollup)
After installation and a reboot, dotnet new console goes through without an error.
Dell forum source: Microsoft Windows 7 Update KB2533623 needed to install Dell Update Package (DUP)
You are using visual studio 2019 older version then you have updated to the latest version has fixed my issue.
Yes. I have delete some files manually from folder.
So i resolved that issue by deleting the unloaded files from that deleted folder as
red cross files will be still in our visual studio if we delete
them outside.
I am supposed to take over a project which is MVC based. in the source code folder, I see all the required files except the sln file. Is there a way to generate the sln file for MVC project? Will it work as expected?
If your project has the .csproj file, then open the .csproj file with Visual Studio, then when you close VS it will ask you to save a .sln file.
To create a .NET class library from the command line, you can run the script
dotnet new classlib
Do that in a clean folder, and it will create a csproj file that can then be opened in Visual Studio 2017.
However, run the script
dotnet new classlib -lang f#
in a clean folder, and the fsproj file that is subsequently create cannot be opened in Visual Studio 2017. The error message reads
The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\FSharp.NET.Sdk\Sdk\Sdk.props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
I have searched for clarification of this issue, and it appears that there is work ongoing to fix it, but I wondered in the interim if there are any add-ins I can install to get this working immediately.
The latest preview releases of Visual Studio and .NET Core support loading .fsproj projects, apparently.
See this comment on the GitHub issue:
Closing this now, as these projects load with 15.3. The current way to use them:
Download VS 2017 Update 3 Preview 3 (or a further preview if it's released and you're reading this)
Download the latest CLI/SDK from here: https://github.com/dotnet/cli/tree/release/2.0.0#installers-and-binaries
(Yes, the .NET SDK is independent of VS. You will also need this to get .NET Core 2.0 support in VS 2017 Update 3 Previews).
I cloned the ASP.NET Core SignalR Repo locally, and try opening the solution from within the following environment.
IDE
Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01055
DOT NET CLI
λ dotnet --info
.NET Command Line Tools (1.0.0-preview2-1-003177)
Product Information:
Version: 1.0.0-preview2-1-003177
Commit SHA-1 hash: a2df9c2576
Runtime Environment:
OS Name: Windows
OS Version: 6.1.7601
OS Platform: Windows
RID: win7-x64
I end up seeing a lot of these kinds of error messages:
..\Repos\SignalR\src\Microsoft.AspNetCore.SignalR\Microsoft.AspNetCore.SignalR.csproj
: error : The default XML namespace of the project must be the
MSBuild XML namespace. If the project is authored in the MSBuild 2003
format, please add
xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the
element. If the project has been authored in the old 1.0 or
1.2 format, please convert it to MSBuild 2003 format. ..\Repos\SignalR\src\Microsoft.AspNetCore.SignalR\Microsoft.AspNetCore.SignalR.csproj
I want to know how to fix this the correct way.
The projects you are trying to open are in the new .NET Core csproj format. This means you need to use Visual Studio 2017 which supports this new format.
For a little bit of history, initially .NET Core used project.json instead of *.csproj. However, after some considerable internal deliberation at Microsoft, they decided to go back to csproj but with a much cleaner and updated format. However, this new format is only supported in VS2017.
If you want to open the projects but don't want to wait until March 7th for the official VS2017 release, you could use Visual Studio Code instead.
I ran into this issue while opening the Service Fabric GettingStartedApplication in Visual Studio 2015. The original solution was built on .NET Core in VS 2017 and I got the same error when opening in 2015.
Here are the steps I followed to resolve the issue.
Right click on (load Failed) project and edit in visual studio.
Saw the following line in the Project tag: <Project Sdk="Microsoft.NET.Sdk.Web" >
Followed the instruction shown in the error message to add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to this tag
It should now look like:
<Project Sdk="Microsoft.NET.Sdk.Web" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
Reloading the project gave me the next error (yours may be different based on what is included in your project)
Saw that None element had an update attribute as below:
<None Update="wwwroot\**\*;Views\**\*;Areas\**\Views">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
Commented that out as below.
<!--<None Update="wwwroot\**\*;Views\**\*;Areas\**\Views">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>-->
Onto the next error: Version in Package Reference is unrecognized
Saw that Version is there in csproj xml as below (Additional PackageReference lines removed for brevity)
Stripped the Version attribute
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" />
I now get the following:
Bingo! The visual Studio One-way upgrade kicked in! Let VS do the magic!
The Project loaded but with reference lib errors.
Fixed the reference lib errors individually, by removing and replacing in NuGet to get the project working!
Hope this helps another code traveler :-D
#DavidG's answer is correct, but I would like to add that if you're building from the command line, the equivalent solution is to make sure that you're using the appropriate version of msbuild (in this particular case, it needs to be version 15).
Run msbuild -version to see which version you're using or where msbuild to check which location the environment takes the executable from and update (or point to the right location of) the tools if necessary.
Download the latest MSBuild tool from here.
If getting this error trying to build .Net Core 2.0 app on VSTS then ensure your build definition is using the Hosted VS2017 Agent queue.
I was getting the same messages while I was running just msbuild from powershell.
dotnet msbuild "./project.csproj" worked for me.
if the project is not a big ,
1- change the name of folder project
2- make a new project with the same project (before renaming)
3- add existing files from the old project to the new project (totally same , same folders , same names , ...)
4- open the the new project file (as xml ) and the old project
5- copy the new project file (xml content ) and paste it in the old project file
6- delete the old project
7- rename the old folder project to old name
I had the same problem and solved it by using dotnet instead of msbuild.
When creating new projects with .net-core (dotnet new -l F#), the projects are created with a project.json file and no fsproj file. However, it is my understanding that an fsproj file is needed in order to get intellisense.
Are there any tools for generating an fsproj file from a project.json file?
I am interested in a solution that works both in Linux and Visual Studio as I use both equally for fsharp.
If you open project.json in Visual Studio 2015 with update 3, it will create an xproj file for the project.
I'm not aware of a way of doing this in linux.
However, as far as I know you don't need an fsproj file to get intellisense.
I found projekt useful for creating and manipulating .fsproj files. However, it will not automatically convert your project.json for you.