问题
I have a merge task in the publisher area of my CruiseControl.NET project that successfully copies a collection of html and png files to the artifacts directory. I've enabled the HtmlReportPlugin in the dashboard like this:
<buildPlugins>
<buildReportBuildPlugin>
<xslFileNames>
<xslFile>xsl\header.xsl</xslFile>
<xslFile>xsl\compile.xsl</xslFile>
<xslFile>xsl\modifications.xsl</xslFile>
<xslFile>xsl\MsTestSummary2010.xsl</xslFile>
</xslFileNames>
</buildReportBuildPlugin>
<buildLogBuildPlugin />
<xslReportBuildPlugin description="MSTest2010 Report" actionName="MSTestBuildReport2010" xslFileName="xsl\MsTestReport2010.xsl"></xslReportBuildPlugin>
<xslReportBuildPlugin description="MSTest Coverage 2010" actionName="MSTestBuildCoverReport2010" xslFileName="xsl\MsTestCover2010.xsl"></xslReportBuildPlugin>
<htmlReportPlugin description="Html Report" actionName="HtmlReport" htmlFileName="index.html" />
</buildPlugins>
The index.html is served just fine, but relative links within index.html don't seem to work. Here's the source to index.html:
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN'
'http://www.w3.org/TR/html4/frameset.dtd'>
<html><head><title>
all.cov
</title>
<meta http-equiv=Content-Type content='text/html;charset=utf-8'>
</head>
<frameset cols='25%,75%'>
<frame src=nav-folder.html>
<frame name=right src=p0.html>
<noframes>
<p>Your browser does not support frames. See <a href=nav-folder.html>nav-folder.html</a>
</noframes>
</frameset>
</html>
And here's one of the errors that I get when loading index.html (replace 'nav-folder' with 'p0' for the other error message):
Server Error in '/' Application.
Unknown object name : nav-folder
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ApplicationException: Unknown object name : nav-folder
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ApplicationException: Unknown object name : nav-folder]
Objection.ObjectionStore.GetByName(String name) +307
ThoughtWorks.CruiseControl.WebDashboard.MVC.Cruise.CruiseActionFactory.CreateHandler(String actionName) +231
ThoughtWorks.CruiseControl.WebDashboard.MVC.Cruise.CruiseActionFactory.Create(IRequest request) +38
ThoughtWorks.CruiseControl.WebDashboard.MVC.RequestController.Do() +155 ThoughtWorks.CruiseControl.WebDashboard.MVC.ASPNET.HttpHandler.ProcessRequest(HttpContext context) +651
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +625 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +27
If I use RetrieveBuildFile.aspx on either of the reference files (for example, http://localhost/server/local/project/Code_Coverage/build/log20120809181334Lbuild.168.xml/RetrieveBuildFile.aspx?file=p0.html
), the files load without a problem, but as in the first example, any relative files will fail to load.
Is there something I have to do in my CruiseControl.NET web.config to get IIS to correctly resolve relative file paths? I am using CruiseControl.NET 1.8.0 and I am running IIS 7 running on Windows 2008, and I have verified that the same issue occurs on a CruiseControl.NET 1.6?? on IIS running on Windows 7.
回答1:
Unfortunately HTML tidy didn't like the Bullseye CodeCoverage HTML as it contains invalid HTML. So that solution won't work.
CruiseControl uses a regular expression to find source links, but this isn't perfect because it misses the case where HTML attributes don't have quotes and it could match string fragments that are not HTML attributes. I've modified the CruiseControl.NET source code to use the HtmlAgilityPack to parse the HTML and this seems to work very well (at least on my test cases.)
回答2:
If you need to solve this problem (without looking on your own where CCnet parses html). I'm using ReportGenerator with CCnet. Here's an example:
In class:
BuildFileDownload (namespace ThoughtWorks.CruiseControl.WebDashboard.Plugins.BuildReport)
Modify Execute procedure by using this code:
HtmlDocument doc = new HtmlDocument();
doc.OptionAddDebuggingAttributes = false;
doc.OptionAutoCloseOnEnd = false;
doc.OptionCheckSyntax = false;
doc.OptionFixNestedTags = false;
doc.OptionOutputOptimizeAttributeValues = false;
doc.LoadHtml(htmlData);
var nodes = doc.DocumentNode.SelectNodes("//a[@href]");
if (nodes != null)
{
foreach (var link in nodes)
{
HtmlAttribute att = link.Attributes["href"];
if (!att.Value.StartsWith("data:") && !att.Value.StartsWith("#") && !att.Value.StartsWith("http://"))
att.Value = @"RetrieveBuildFile.aspx?file=coverageReport\" + att.Value;
}
htmlData = doc.DocumentNode.WriteTo();
}
nodes = doc.DocumentNode.SelectNodes("//link[@href]");
if (nodes != null)
{
foreach (var link in nodes)
{
HtmlAttribute att = link.Attributes["href"];
if (!att.Value.StartsWith("data:") && !att.Value.StartsWith("#") && !att.Value.StartsWith("http://"))
att.Value = @"RetrieveBuildFile.aspx?file=coverageReport\" + att.Value;
}
htmlData = doc.DocumentNode.WriteTo();
}
Remember to get rid of old regEx parsing first. It's a sample code but it fits all my needs. This solution uses HtmlAgilityPack. Note that path given as a prefix for new attribute value may differ.
回答3:
The issue was that CruiseControl.NET doesn't like HTML with attributes with values that aren't quoted. I'm using output generated by Bullseye CodeCoverage and that output has attributes with values that aren't quoted. I'm using HTML Tidy to add quotes.
来源:https://stackoverflow.com/questions/11909271/relative-links-not-working-in-cruisecontrol-net-htmlreportplugin