Domanda

How can I run FxCop against an ASP.net Web-site?

Background

I have an ASP.net Web-site that I want to run FxCop against.

Note: I have an ASP.net web-site, not an ASP.net web-application, that I want to run FxCop against.

How can I run FxCop against an ASP.net web-site in Visual Studio 2010 Professional?


Some people suggest that it's very simple: just right-click the web-site project, and click Run Code Analysis on Web Site:

The process it very simple.... just right click on the web site project and "Run Code Analysis on Web Site"

What they ignore is that no such option exists:

enter image description here


I also tried Tools menu -> FxCop. But of course that doesn't work because its command line options:

FxCopCmd.exe /c /f:$(TargetPath) /d:$(BinDir) /r:"C:\Program Files (x86)\Microsoft Fxcop 10.0\Rules"

Doesn't make sense for web-sites.


Someone has suggested, correctly, that it's not possible, because there is no assembly for FxCop to validate:

The build process in ASP.NET 2.0 is very different than in ASP.NET 1.x, because it does not produce a dll file.

That means that you cannot use FxCop because it can only work with dll and exe file types.

That means that short of compiling the entire web-site into an assembly, you cannot run FxCop against an ASP.net web-site.

How can I run FxCop against an ASP.net web-site?

È stato utile?

Soluzione

A workaround is to pre-compile your web site,

  1. Pre-compile your web site using aspnet_compiler.exe, http://msdn.microsoft.com/en-us/library/bb398860(v=vs.100).aspx
  2. Run FxCop on the result of precompilation.

You could not see the "Run Code Analysis on Web Site" because your Visual Studio edition is not high end enough (Microsoft should be blamed as such essential features should be there in all editions).

Altri suggerimenti

You can publish your website, it will generate dlls on which you can run fxcop.

Use-FxCop-with-ASPNET-20


The build process in ASP.NET 2.0 is very different than in ASP.NET 1.x, because it does not produce a dll file. That means that you cannot use FxCop because it can only work with dll and exe file types. However, there is a way to produce dll files from your web application within Visual Studio 2005 and those dll files can be used by FxCop.

These are the steps to follow to make FxCop analyse your web application:

Step 1

Create a new folder somewhere on the disk. It could be C:\deploy

Step 2

Publish the web application into the new folder

enter image description here

enter image description here

Step 3

Open FxCop and add all the dll files from the newly created bin folder (C:\deploy\bin) to be analyzed.

enter image description here

For those of us not using Visual Studio Team System, these are the steps we need to follow to analyse our web applications in FxCop. Let’s hope the next version of Visual Studio have fixed this issue.

Or you can run a tool that does analysis on source code, not compiled assemblies. Might save some of your valuable time.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top