The Run Code Analysis function is missing in Visual Studio 2017 when using new csproj format - code-analysis

I want to use the Visual Studio Code analyser for my new .netstandard libray project.
But when I right click on the project there is no analyse menu item anymore.
It seems that all projects which use the new csproj formats cannot be analysed with the analyser.
Does anybody has experience with this? Or has a clue whom to ask?
Update:
If I add the following to the csproj file:
<RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisRuleSet>...</CodeAnalysisRuleSet>
and when I then build the project with MSBuild 15 it will run the code anaysis and generates the following warning:
MSBUILD : warning : CA0068 : Debug information could not be found for target assembly 'CodeAnalyseTest.dll'. For b
est analysis results, include the .pdb file with debug information for 'CodeAnalyseTest.dll' in the same directory a
s the target assembly.
But the .pdb is there. When I add now a
<DebugType>Full</DebugType>
to the csproj and then rebuild it with msbuild the code analyse works well.
Update 2
I opened a ticket on GitHub: https://github.com/dotnet/sdk/issues/1086

Related

Why does Visual Studio 2022 display an error message when editing dependencies "String value ' ' cannot be translated to any value from System.Guid."?

I have a project which I am using as a simple testbed for a graphical application. I am attempting to add a shared project file (.shproj), but whenever I try to edit the project's dependencies, I get a dialog which says:
---------------------------
Microsoft Visual Studio
---------------------------
String value '
' cannot be translated to any value from type System.Guid.
---------------------------
OK
---------------------------
This happens if I right-click on my project and select either **Add Project Reference..." or "Add Shared Project Reference..."
Unfortunately I do not have this project as part of source control so I can't go back in time to see what may have caused this problem. I have attempted to undo the operations which may have gotten me into this state (such as adding the .shproj to my solution) but the dialog still appears when I attempt to edit the dependencies.
I haven't been able to find anything online about this error, and I suspect it's happening because something is malformed in either my .csproj or the .sln, but I'm not sure where to look or what to try to solve this.
I am running Visual Studio 2022 (17.4.2).
I have tried opening the project in Visual Studio 2019 and I can edit the dependencies there. I can also add and remove nuget packages. Note that if I modify the dependencies in Visual Studio 2019, the project will correctly load and build in 2022 so I do have a workaround. However, it would be nice to know why the project dependencies cannot be edited in 2022.
It turns out that empty Project tags caused problems in the .csproj file.
My .csproj file referenced other .csproj files and these references included empty Project tags.
Here is a snippet before the fix:
<ProjectReference Include="../../../GitHub/FlatRedBall/Engines/FlatRedBallXNA/FlatRedBallDesktopGLNet6/FlatRedBallDesktopGLNet6.csproj">
<Name>FlatRedBallDesktopGLNet6</Name>
<Project>
</Project>
</ProjectReference>
Removing the Project tags solves this problem, as shown in the following code:
<ProjectReference Include="../../../GitHub/FlatRedBall/Engines/FlatRedBallXNA/FlatRedBallDesktopGLNet6/FlatRedBallDesktopGLNet6.csproj">
<Name>FlatRedBallDesktopGLNet6</Name>
</ProjectReference>

Up-To-Date check claims missing build output since VS 2019

Since I am using Visual Studio 2019, some of my old projects are rebuild every time I, even though nothing changed. Build output states the following:
Up-To-Date check: Project: ..\MyProject.vcxproj, Configuration: Debug Win32
Project is not up-to-date: build output 'd:\mysolution\myproject\debug\' is missing
The mentioned output directory does exist, but with capitalization (D:\MySolution\MyProject\Debug)
Building the same project in Visual Studio 2017, MSBuild correctly detects when nothing has changed:
Up-To-Date check: Project: MyProject, Configuration: Debug Win32
All outputs are up-to-date.
The problematic projects are managed C++ projects, configured platform toolset is "Visual Studio 2013 (v12)".
Try:
Clean the solution,close the solution and VS
Delete the .suo file(or .vs folder) and bin and obj folders
Open VS2019, re-ref the dlls,change ref path in .xxproj file
See this similar issue.
If the issue persists, please check if you've set the output path with an absolute path. Always the output dir should be a relative path by default:
Update:
Now I think I've located the cause of the issue, some mistake in your project file mess up the build process.
Please check this:
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
...
<ProgramDataBaseFileName>$(Configuration)\</ProgramDataBaseFileName>
<!--<ProgramDataBaseFileName>$(Configuration)\$(TargetName).pdb</ProgramDataBaseFileName>-->
<CompileAsManaged>true</CompileAsManaged>
<PrecompiledHeaderFile />
</ClCompile>
The value of ProgramDataBaseFileName is $(Configuration)\, which is debug\. So the build process thinks there exist a build output file named debug\, but it actually doesn't exist. Then the Up-To-Date check can't work normally!
Here is the workaround:
So you can either comment that statement or gives it right value like $(Configuration)\$(TargetName).pdb instead of $(Configuration)\ which is a path not a file.
<!--<ProgramDataBaseFileName>$(Configuration)\</ProgramDataBaseFileName>--> or <ProgramDataBaseFileName>$(Configuration)\$(TargetName).pdb</ProgramDataBaseFileName> can resolve this issue.
Note: Since the ProgramDataBaseFileName exists in both ItemDefinitionGroup from Debug|win32 and Release|win32, you should correct the value in two places in your .vcxproj file.

MSBuild Error after upgrading TeamFoundation dlls to 2017

So, we were using 2013 TFS dlls in our projects (namely TeamFoundation.Client, TeamFoundation.VersionControl.Client, and TeamFoundation.Common). I recently upgraded the project to use 2017 versions of the above mentioned dlls (We have VS2017). I am getting them from the below folder.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer
After upgrading, when I build my solution, I get the following error:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\Microsoft.NET.Build.Extensions.NETFramework.targets(56,5): warning : Resolved file has a bad image, no metadata, or is otherwise inaccessible. The system cannot find the path specified. (Exception from HRESULT: 0x80070003)
I am not familiar with MSBuild so not sure how to proceed.
The error takes me to the following line in the MSBuild code:
GetDependsOnNETStandard Condition="'$(_RunGetDependsOnNETStandard)' == 'true'"
References="#(_CandidateNETStandardReferences)">
<Output TaskParameter="DependsOnNETStandard" PropertyName="DependsOnNETStandard" />
</GetDependsOnNETStandard>
There is an outstanding issue with Visual Studio 2017 and DependsOnNETStandard that should hopefully be resolved in 15.8
I just encountered the same problem today when upgrading a project that was originally created VS 2015 and upgraded to VS 2017.
It looks like the upgrade of the projects misses a few elements in the XML that it needs.
If you edit the csproj files of the effected projects and add
<DependsOnNETStandard>false</DependsOnNETStandard>
to the top PropertyGroup like so:
<PropertyGroup>
...
<DependsOnNETStandard>false</DependsOnNETStandard>
</PropertyGroup>
It should resolve the issue. It did for me.
Details of the issue and discussion around it can be found at:
https://github.com/dotnet/sdk/issues/1544
According to your error log info, seems you are trying to build locally through Visual Studio or MsBuild command not TFS build.
Suggest you to use the latest version of dlls, Microsoft.TeamFoundationServer.Client and also upgrade your Visual Studio 2017 to latest version. For The system cannot find the path specified. issue try to
Clean All Projects.
Unload All Projects
Reload All Projects.
ReBuild Solution
Another way is :
Close the solution
Delete bin folder
Delete all obj folders
Open solution and build
If all of above still not work, suggest you add a more detail log and sample code for troubleshooting.

How to avoid having (or delete) PDB files in TFS 2012 build result

When using DefaultTemplate from Visual Sturdio 2012 (and TFS 2012 server), the PDB files are included in build directory. I do not want them.
Is there a way not to generate those files during build process?
Or
How can I delete those files?
I found this thread about deletion but seems a bit strange (no delete activity?)
There also is this answer but does not involve XAML template.
Thanks in advance for your help.
PDB files hold debug information on your code and its not advised to disable them, they are valid output hence deployment shouldn't be messing with them.
You can disable their generation in Visual Studio project Properties> Build > Advanced > Debug Info = none.
If you absolutely want them gone then disable them for build specific configuration (relaese etc.)
The build server by default does whatever the Solution (sln) tells it to. That by default is to do a "Debug" build and that created the PDB's. You can tell the Build to do a "Release" build that will not by default create any PDB's...
Figure: Adding a Build Configuration
I would however recommend against it as the PDB's contain information that you need even in production systems. Consider for a moment that you have a DLL in production and the customer is encountering a problem. You get them to create an InteliTrace log so that you can debug it locally (or they let you debug on their environment) and suddenly you are trying to debug without Visual Studio understanding the relationship between the Executable and the Source Code. So no debug...
Since I was unable to find building option to disable PDB file generation, I delete them afterwards.
There is no easy way to delete files. I did:
use a FindMatchingFiles Activity with wildcard *.pdb, which returns
a full path to pdb files
use a Foreach loop
call a DotNet method in the loop for each file with the InvokeMethod Activity,
with target type System.IO.File and method being "Delete"
In the previous version (Visual Studio 2010)
When we build /release, it was not generating PDBs, the PDB files are created when we only build with /debug:full or /debug:pdbonly, we use /debug:pdbonly if we want to generate PDBs for a release build that we do not want to be debuggable.
This is not the case in Visual Studio 2012, I checked it and I found it generated PDBs in both, /debug and /release
There is no documentation for Visuals Studio 2012.

Unable to build solution incrementally: Input file ".NETFramework,Version=v3.5" does not exist

I'm not able to build solution incrementally. I checked diagnostic log and I found that every project containing workflows are always rebuild because of this:
Input file ".NETFramework,Version=v3.5" does not exist.
Workflows are always recompiled, new temporary files are created and project is build again.
Building target "WorkflowCompilation" completely.
Input file ".NETFramework,Version=v3.5" does not exist.
Using "CompileWorkflowTask" task from assembly "System.Workflow.ComponentModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35".
Task "CompileWorkflowTask"
No files found with '.xoml' extension in the set of input files.
Generated temporary code file: C:\Users\Ludwo\AppData\Local\Temp\uwdnm5th.cs
Workflow markup validations completed with 0 errors and 0 warnings.
Done executing task "CompileWorkflowTask".
Done building target "WorkflowCompilation" in project "Delta.Workflow.Common.Merged.csproj".
Target "CoreCompile" in file "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets" from project "h:\Prj\R4x\M\CountrySystems\Delta\Common\Delta.Workflow.Common\Delta.Workflow.Common.Merged.csproj" (target "Compile" depends on it):
Building target "CoreCompile" completely.
Input file "C:\Users\Ludwo\AppData\Local\Temp\uwdnm5th.cs" is newer than output file "obj\Debug\Delta.Workflow.Common.pdb".
I'm building my projects using MSBuild 4.0. My projects are set to build with v3.5 TargetFrameworkVersion, unit tests projects are build with TargetFrameworkVersion set to v4.0. I tried to build it on different PC but the result is still the same. I also played with references in my projects. It seems to be like v4.0/v3.5 conflict, but I don't know how to fix it. Any ideas?
I found it. The root cause is wrong version of Workflow.targets file imported inside my workflow (.csproj) projects. Workflow.targets for .NET v4.0 was imported instead of v3.5. It should be related to projects upgrade from VS2008 to VS2010 I did some time ago.
I changed Workflow.targets Import from
<Import Project="$(MSBuildToolsPath)\Workflow.targets"/>
to
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Windows Workflow Foundation\v3.5\Workflow.targets" />
Hope it helps someone...