We are using Swagger UI documentation to describe our project API. Swagger have to read XML from projectname.xml to show all the C.R.U.D. functions we have in project.
The problem is when I switch from Visual Studio to Visual Studio Code, it is not regenerating or changing existing XML file from Visual Studio Code. Is there the way to generate XML documentation file in Visual Studio Code like in Visual Studio Ultimate for instance, as shown the image below?
You can use the <GenerateDocumentationFile> property in the project file. This is a Boolean, and sets the DocumentationFile property automatically.
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1701;1702;1705;1591</NoWarn>
</PropertyGroup>
(Unfortunately, the Visual Studio project properties UI doesn't expose this improved way to enable XML documentation file generation yet. See this work item in the project system repo, and this pull request, which initially added the feature.)
The following is slightly more robust, it doesn't hard code the framework and project
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\$(TargetFramework)\$(MSBuildProjectName).xml</DocumentationFile>
<NoWarn>1701;1702;1705;1591</NoWarn>
</PropertyGroup>
See David Waterworth's answer as it is more robust.
In your csproj file for the project, add the following.
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\netcoreapp2.0\TodoApi.xml</DocumentationFile>
</PropertyGroup>
Then rebuild your project.
Related
We have an issue with Visual Studio 2019 found when trying to pre-compile our ASP.Net project during publish. We got errors such as:
error CS1056: Unexpected character '$'
When I look at the view, it is using string interpolation.
All the projects in this solution are set to target full .Net Framework 4.6.1. From what I read, that should default to C# 7.3 compiler.
I have updated the DomCompiler and Compiler packages to version 3.6.0. In the web.config I tried to set c# version to both default and 7 specifically. The error occurs no matter which one is used.
I also tried to add LangVersion to the .csproj file and specify 7, but that didn't work either.
If we deploy not pre-compiled these views work, so the run time on the server is usually the correct c# compiler version. This is only a dev time and build time issue.
Visual Studio 2019
Visual Studio 2019 chooses the language version by default:
Right click on your project and select Properties
Choose Build and click the Advanced button
click on Why cant's I select a different version?
The latest C# compiler determines a default language version based on
your project's target framework or frameworks. Visual Studio doesn't
provide a UI to change the value, but you can change it by editing the
csproj file. The choice of default ensures that you use the latest
language version compatible with your target framework.
If you want to override the language version you have 3 options:
Manually edit your project file.
Set the language version for multiple projects in a subdirectory.
Configure the -langversion compiler option.
The first option seems to achieve your goal, open the project file in your favorite text editor and add the language version, e.g:
MyProject.csproj
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<!--<LangVersion>preview</LangVersion>-->
<!--<LangVersion>7.3</LangVersion>-->
</PropertyGroup>
</Project>
Visual Studio 2017
Right click on your project and select Properties
Choose Build and click the Advanced button
Here you can choose your Language version
Change language version for all of the projects at one go
If you have several projects in your solution and you want to create a configuration to change the language version for all the projects at one go, then you need to create a file name Directory.Build.props at the root of your repository. You can configure the language version in this file, for example:
Directory.Build.props
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<!--<LangVersion>preview</LangVersion>-->
<!--<LangVersion>7.3</LangVersion>-->
</PropertyGroup>
</Project>
See this question for detailed explanation.
You can not use c# 7 with .Net framework projects targeting 4.6.1. It does not matter which visual studio version you're using.
Please check this link:
https://www.tutorialsteacher.com/csharp/csharp-version-history
I had the same problem (not being able to use all language features) while using (.net 4.5.2)
In Visual Studio 2019 Web Projects, file nesting in the Solution Explorer works like a charm. If you add a file named ClassA.cs and another file named ClassA.Custom.cs they get nested as it should be.
But for Class or Shared Library Projects it doesn't work at all. It doesn't matter if you change the settings to "Default" or "Web" or even add a custom File Nesting Setting.
Is there a way, to configure Visual Studio 2019 so that file nesting also works in Class Library Projects and alike?
I know one could change the *.csproj files manually to add Entries with the <DependentUpon> Tag like it was in earlier Visual Studio versions, but i really don't like the idea of changing this manually for all the classes i have.
<Compile Update="$(ProjectDir)\Person.*.cs">
<DependentUpon>$(ProjectDir)\Person.cs</DependentUpon>
</Compile>
For the people using Visual Studio 2022 and non-web projects, this is the solution from Github that helped me to fix it.
To enable configurable file nesting for non-web projects in VS 2022, add this to your .csproj file:
<ItemGroup>
<ProjectCapability Include="ConfigurableFileNesting" />
<ProjectCapability Include="ConfigurableFileNestingFeatureEnabled" />
</ItemGroup>
Original Answer:
There is an issue about this topic active on Github.com and Developer Community:
Issue 5722
Developer Community 483587
A workaround for this problem exists - at least working for .Net Standard 2.0. Add the following lines to your *.csproj file:
<ItemGroup> <ProjectCapability Include="DynamicDependentFile" /> <ProjectCapability Include="DynamicFileNesting" /> </ItemGroup>
Update:
This issue should be fixed from Visual Studio 2019 Verison 16.7 onwards.
Piggy Backing onto #phihi's answer.
#phihi's solution does actually work with .NET Core 3.1 libraries; but in addition, there must be a .filenesting.json file added at the solution level. It seems that it's also required that the new .filenesting.json lives inside a "Solution Items" folder (folder name may not matter) at the solution level.
Desired nesting settings can be optionally defined stand-alone.. instead of creating a new file with ALL existing default settings, as long as you set "root": false - this essentially appends settings onto the existing default configuration without losing any default settings.
Great success 🤘
I faced this issue with the Class Library project on .net6. Instead of using the Class Library template use Razor Class Library.
Template window
You want the Razor Component option to be in place in the Add new item window.
Available item templates
Using VSTS (not git) and use Visual Studio 2017 libman to manage client-side libraries. These libraries are put in wwwroot\lib. I don't want to add these to source code control.
I've tried putting a .tfignore in my project folder with:
wwwroot\lib
I also tried:
\wwwroot\lib
Regardless of what I do, all the wwwroot\lib files are put in source code control when I add a new client-side library via libman.
How can I ignore the lib files since they are managed/restored by Visual Studio libman feature?
Based on the comment above from Seabizkit, **/wwwroot/lib worked for me.
I am using Visual Studio Enterprise 2017 to develop my .net core projects.
My solution also has some unit test projects and I want to view my current Code coverage.
When I clicked Test -> Analyze Code Coverage -> All tests. All my unit tests ran but in Code Coverage Results it only reported code coverage for my unit test projects which doesn't make any sense to me.
Question 1: Do you guys experience the same issue with me? Any solution for this? I also need to set up build definition in VSTS to report code coverage.
Question 2: Also when I right clicked to debug 1 of my unit test. It executes ALL of my unit tests. Is this a bug in VS2017?
Update1: I found this topic: https://github.com/Microsoft/vstest/issues/597
Even with the "fixed" version I had issues (Only able to see code coverage for the test projects, not the actual projects I was testing). To workaround the problem I removed the <DebugType>Full</DebugType> from the test project.
So, as a summary:
Add package Microsoft.CodeCoverage (1.0.3) into your test project.
Add the <DebugType>Full</DebugType> tag on the .csproj file on
the projects we want to see code coverage values (inside <PropertyGroup> as explained on the vstest github link).
Run unit tests.
On the "Test Explorer" select passed unit tests, right click -> "Analyze Code Coverage for Selected Tests".
You should see code coverage for your assemblies.
My setup (Minimal setup?)
xunit (2.3.1)
xunit.runner.visualstudio (2.3.1)
Microsoft.NET.Test.Sdk (15.3.0)
Microsoft.CodeCoverage (1.0.3)
Visual Studio Enterprise 2017 (15.4.1)
You can try dotCover from Jetbrains. https://www.jetbrains.com/dotcover/features/
dotCover is a .NET unit testing and code coverage tool that works right in Visual Studio, helps you know to what extent your code is covered with unit tests, provides great ways to visualize code coverage, and is Continuous Integration ready. dotCover calculates and reports statement-level code coverage in applications targeting .NET Framework, Silverlight, and .NET Core.
It works fine with .NET Core & can show code coverage.
Supports multiple unit testing frameworks, namely MSTest, NUnit, xUnit (all out of the box) and MSpec (via a plug-in).
Based on this article (Code Coverage does not work in the IDE with netcoreapp1.x projects (VS 2017 RTM):
Code coverage is currently not implemented for netcore projects. The
work on this issue is in progress, it will come as part of post RTW
releases.
It looks like they are still working out the infrastructure (data collectors) bits before releasing. They are supposedly close.
https://github.com/Microsoft/vstest/issues/579
This issue has been fixed with Version 15.3:
https://github.com/Microsoft/vstest-docs/blob/master/docs/analyze.md#coverage
JDC's answer helped me to include my actual projects but I could not get rid of the test projects in the coverage report.
I managed it by adding a "CodeCoverage.runsettings" in my XUnit test project with the following content:
<?xml version="1.0" encoding="utf-8"?>
<!-- File name extension must be .runsettings -->
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Configuration>
<CodeCoverage>
<ModulePaths>
<Exclude>
<ModulePath>.*\.Tests.dll$</ModulePath>
<!-- Add more ModulePath nodes here. -->
</Exclude>
</ModulePaths>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
The important part here is to exclude the test project in the ModulePaths section.
Using the latest stable of CC.NET (new to it) and VS 2010.
I have defined project files for simple C# projects (4 in total) and one MVC Project.
The C# projects all compile correctly; however, the MVC3 project refuses to build.
I receive the following error in CC.NET:
error MSB4019: The imported project
"C:\Program
Files\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets"
was not found. Confirm that the path
in the declaration is
correct, and that the file exists on
disk.
After searching around and finding This link
and This other link (both referring to older versions of Visual Studio), it seemed that the general solution was to copy these files from that directory to the solution directory, add them to the solution with visual studio, and then change this line in the .csproj file:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
To this:
<Import Project="$(SolutionDir)\Microsoft.WebApplication.targets" />
However, this technique that worked for other VS Versions produces a different result in VS 2010: I receive the .NET Project upgrade wizard, as if upgrading the project from an old version of .NET. This strangeness is compounded by the fact that even if I do an undo and re-save the file exactly as it was, I receive the same message. It's as if the project has been marked dirty or something else has changed somehow.
Anyone have any ideas? This seems like it should be easier, but I can't seem to find another resource on it anywhere. Hoping StackOverflow will come through per usual. :)
Thanks in advance for any help!
The .targets file for v10.0 also has an assembly in the install folder - Microsoft.WebApplication.Build.Tasks.dll. Did you copy that file over as well? That will likely be necessary for the .targets file to work correctly, though that may not be the cause of your problem.
It sounds like CC.Net isn't getting a proper reference to the msbuild executables.
Trying installing both of these on your build server (that's who I was able to get past that exact error).
Links :
Windows SDK .Net 4
VS2010 Integrated Shell