Help Updating XML file using MSBuild Extensions 4 with namespaces - msbuild-4.0

I'm having some trouble getting MSBuild extensions 4.0 to update an XML file once a namespace is involved.
When I have a simple XML file with no namespace then fine, but once i attempt to update an xml file that has a namespace set, then nothing happens .. notice there is no error tho.
Here are the simple ones that work fine
<Project>
<PropertyGroup>
<ApplicationVersion>5.1.500.16</ApplicationVersion>
</PropertyGroup>
<PropertyGroup>
<ApplicationVersion>old</ApplicationVersion>
</PropertyGroup>
</Project>
and project file
<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TPath>C:\Program Files\MSBuild\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks</TPath>
<AssemblyVersion>5.1.500.18</AssemblyVersion>
</PropertyGroup>
<Import Project="$(TPath)"/>
<Target Name="Default">
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="RemoveElement" " File="c:\build\test.csproj" XPath="/Project/PropertyGroup[1]/ApplicationVersion" />
</Target>
</Project>
Wheras these dont do anything !
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://mynamespace">
<PropertyGroup>
<ApplicationVersion>5.1.500.16</ApplicationVersion>
</PropertyGroup>
<PropertyGroup>
<ApplicationVersion>old</ApplicationVersion>
</PropertyGroup>
</Project>
and
<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TPath>C:\Program Files\MSBuild\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks</TPath>
<AssemblyVersion>5.1.500.18</AssemblyVersion>
</PropertyGroup>
<Import Project="$(TPath)"/>
<ItemGroup>
<Namespaces Include="Mynamespace">
<Prefix>me</Prefix>
<Uri>"http://mynamespace"</Uri>
</Namespaces>
</ItemGroup>
<Target Name="Default">
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="RemoveElement" Namespaces="#(Namespaces)" File="c:\build\test.csproj" XPath="//me:Project/PropertyGroup[1]/ApplicationVersion" />
</Target>
</Project>
So what's the deal ? what am i missing ? Is it the formatting of the XPath in the second instance ? I've tried all kinds of variations.

Try this:
<Target Name="Default">
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="RemoveElement" Namespaces="#(Namespaces)" File="c:\build\test.csproj" XPath="//me:Project/me:PropertyGroup[1]/me:ApplicationVersion" />
</Target>
(namespace prefix before each xpath element)

In addition to the advice given in the other answer, remove the quotes from the Uri metadata in the Namespace item.
Note that according to the note for the prefix parameter in the MSDN documentation, specifing the empty string for the Prefix metadata will never work.

Related

Checkstyle generate incompleted XML report

I run Checkstyle with Ant. Some projects work correctly, however, there's one project with very strange result. The XML report is not completed, no end tag and in the last line, the full path of JAVA file is not commpleted.
I copy some lines to here, after hide some sensitive information:
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="8.43">
<file name="D:\projects\service-impl\src\com\a\b\c\d\e\f\v1_0\identification\impl\AServiceAdapterImpl.java">
</file>
<file name="D:\projects\service-impl\src\com\a\b\c\d\e\f\v1_0\identification\impl\sdo1.java">
</file>
<file name="D:\projects\service-impl\src\com\a\b\c\d\e\f\v1_0\identification\impl\dto2.java">
</file>
<file name="D:\projects\service-impl\src\com\a\b\c\d\e\f\v1_0\identification\impl\sdo3.java">
</file>
.....
And these last line of file:
<file name="D:\projects\service-impl\test\com\a\b\x\y\z\international\converter\convert1.java">
</file>
<file name="D:\projects\service-impl\test\com\a\b\x\y\z\international\converter\XConverterTest.java">
</file>
<file name="D:\projects\service-impl\test\com\a\b\x\y\z\international\con
No end tag, the last line is not completed.
And no thing show ion console.
How can I fix it
Solved, the new Checkstyle version don't support UTF8 method name/field name. After rename those variable, it works!

How to be alerted of razor view errors

My dotnet core projects build and deploy with no errors, but I could have a honking game breaking exception in a cshtml view that doesn't get picked up at all. In an ideal world I'd have tests checking every crud page, but not on this project, client doesn't have the budget. There's too many views to open them all and check as well (every time)
Is there any way to have the build fail if there's any bad code in the cshtml files?
This will be the default in ASP.NET Core 2.1 since views will be always compiled on build and only dynamically re-compiled on edits.
In the meanwhile, you can add this to your csproj file (built this originally on this GitHub issue):
<Target Name="SetMvcRazorOutputPath">
<PropertyGroup>
<MvcRazorOutputPath>$(IntermediateOutputPath)</MvcRazorOutputPath>
</PropertyGroup>
</Target>
<Target Name="_MvcRazorPrecompileOnBuild"
DependsOnTargets="SetMvcRazorOutputPath;MvcRazorPrecompile"
AfterTargets="Build"
Condition=" '$(IsCrossTargetingBuild)' != 'true' " />
<Target Name="IncludePrecompiledViewsInPublishOutput"
DependsOnTargets="_MvcRazorPrecompileOnBuild"
BeforeTargets="PrepareForPublish"
Condition=" '$(IsCrossTargetingBuild)' != 'true' ">
<ItemGroup>
<_PrecompiledViewsOutput Include="$(MvcRazorOutputPath)$(MSBuildProjectName).PrecompiledViews.dll" />
<_PrecompiledViewsOutput Include="$(MvcRazorOutputPath)$(MSBuildProjectName).PrecompiledViews.pdb" />
<ContentWithTargetPath Include="#(_PrecompiledViewsOutput->'%(FullPath)')"
RelativePath="%(_PrecompiledViewsOutput.Identity)"
TargetPath="%(_PrecompiledViewsOutput.Filename)%(_PrecompiledViewsOutput.Extension)"
CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
</Target>

Overriding/merging standard programmatic configuration with config file section

We have a standard set of conventions that we follow for logging from our various applications, and it is sensible to package this configuration as by-code configuration and include in a common assembly.
Occasionally, however, we need to override this config to more efficiently debug production issues. This is more easily accomplished by letting a developer or administrator add an NLog config section, which can be read in and override or add to configuration done programmatically.
Can this be done out of the box with NLog?
I know this isn't by-code (I'm not sure how to do it), but you can use <include> with XML config to override things like variables. Here's a sample that uses Web.config that overrides the "standard" NLog.config for other projects:
Web.config:
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<include file="${basedir}\bin\NLog.config" />
<variable name="fruit" value="Apples" />
</nlog>
</configuration>
NLog.config (that gets copied to bin):
<?xml version="1.0"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<!-- Output Window -->
<target name="debug" xsi:type="Debugger" layout="${fruit}|${level:uppercase=true}|${logger}|${message}"></target>
</targets>
<rules>
<logger name="*" writeTo="debug" />
</rules>
</nlog>

Converting a Portable Class Library Project .csproj file from Version 2 (Beta) back to Version 1

I'm trying to move a lot of code backwards and forwards between the VS10, VS11 and MonoDevelop3 a lot at present.
It seems that MonoDevelop3 has some initial support for PCL1, but VS10 and VS11 are now both using PCL2(Beta) - because I installed VS11 on the same PC as VS10.
In order to allow MonoDevelop3 to load these PCL2(Beta) projects, I'm trying to manipulate the PCL projects by hand.
It seems like this is not just as simple as changing the TargetProfile in the .csproj XML file - it seems like more is needed... but I can't work out what.
Does anyone know what the exact differences are between PCL2 and PCL1? Or how I might manually convert PCL2 project files so that they can be loaded into MonoDevelop?
Thanks
Stuart
An example PLP2 project file looks a bit like:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B6E27475-E7D0-448C-A5CC-5097DCA1E2DD}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Cirrious.MvvmCross</RootNamespace>
<AssemblyName>Cirrious.MvvmCross</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile104</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows" />
</ItemGroup>
<ItemGroup>
<Compile Include="Application\MvxApplication.cs" />
etc
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
</Project>
Closing this question now.
After looking into this at great length... it seems there aren't any significant differences between the project files.
Instead, it seems that the monoDevelop support for these files is still in its youth and you must use Profile1 if you want these files to open in MonoDevelop (3.0.2)
So use:
<TargetFrameworkProfile>Profile1</TargetFrameworkProfile>
Not
<TargetFrameworkProfile>Profile2</TargetFrameworkProfile>

how can i create a html report for the junit xml report manually?

I have run junit and it shows the results in Junit console, then i do a export of the result, it is saved as some test.xml. now i want to generate a html report out of it how do i do it ? MY project is complex and i cant do as a normal
<target name ="test" depends="run-tests">
<junitreport todir="${reports}">
<fileset dir="${reports}/raw/">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${reports}\html\"/>
</junitreport>
</target>
anybody any tool that can be used to convert the results in xml to a html format.
Given just the junit xml file (and python) you can convert the xml junit report file into a single self-contained HTML file using junit2html. https://github.com/inorton/junit2html
I had wanted a tool that does this for quite a long time so finally sat down the other day and had a go. It is pure python so should work on any platform as a stand-alone tool.
Not 100% sure what you're asking but heck here's my ant code for doing a JUnit batch test then a HTML report using the XML formatter...
<junit showoutput="on" printsummary="on" fork="false" haltonfailure="false"
failureproperty="unittest.failure">
<classpath>
<pathelement path="${build.classpath}"/>
<pathelement path="${classes}"/>
</classpath>
<batchtest todir="${unittests.results}">
<fileset dir="${classes}">
<include name="${batchtest.prefix}#{test}_test.class" />
</fileset>
<formatter type="xml"/>
</batchtest>
</junit>
<junitreport todir="${unittests.results}">
<fileset dir="${unittests.results}"/>
<report todir="${unittests.results}"/>
</junitreport>
note that the #{test} is because its part of a macrodef within the build.xml file.
From what you said in the question, its unsure if you're using the <formatter type="xml">.
Anyway hope that helps
oh and dont mix your slashes ${reports}\html\" > ${reports}/html/"