How to be alerted of razor view errors - razor

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>

Related

How to update a regular C++ project to a CUDA runtime project in VS?

How can I update a regular VC++ project into a CUDA runtime project in Visual Studio 2019?
I tried to add the CUDA markups of the vcxproj project file, without success.
I'm expecting to see the CUDA/C++ tree in project properties.
In <Project DefaultTargets="Build" there should be:
<PropertyGroup>
<CUDAPropsPath Condition="'$(CUDAPropsPath)'==''">
$(VCTargetsPath)\BuildCustomizations</CUDAPropsPath>
</PropertyGroup>
it defines the variable CUDAPropsPath used further.
In the same <Project :
<ImportGroup Label="ExtensionSettings">
<Import Project="$(CUDAPropsPath)\CUDA 10.1.props" />
</ImportGroup>
add the default parameters of CUDA/C++ and CUDA/linker in project properties.
For all the .cu files, we need in <ItemGroup> with the other cpp files:
<CudaCompile Include="MyKernel0.cu"/>
And in <ImportGroup Label="ExtensionTargets"> there must be:
<Import Project="$(CUDAPropsPath)\CUDA 10.1.targets" />
that adds the CUDA/C++ and CUDA/linker in project properties.

NoClassDefFoundError when checkstyle is running

I have written a new checkstyle check as a filescanner. I modeled my junits after the code I found in the checkstyle code. The junits run just fine and everything looks good.
But then, I add the check to my project.
<module name="TreeWalker">
<property name="tabWidth" value="4" />
<module name="com.onuspride.codetools.checkstyles.DuplicateClassNames"/>
</module>
and my ant task
<taskdef resource="checkstyletask.properties">
<classpath refid="classpath" />
</taskdef>
<property name="checkstyle.suppressions.file" value="checkstyle/suppressions.xml" />
<property name="translation.severity" value="error" />
<target name="checkStyle" description="TestTask to evaluate the checkstyle system.">
<checkstyle config="checkstyle/checkstyle_checks.xml">
<fileset dir="${msg.src}" includes="**/*.java" />
<formatter type="plain" />
<formatter type="xml" toFile="${msg.build.jar}/checkstyle_errors.xml" />
<classpath refid="classpath" />
</checkstyle>
</target>
the duplicateclassnames class calls several classes in the same jar. For some reason, when ant runs it, ant finds the check class, but can't find the supporting classes, when they are all in the same jar file. here's what i get in ant
[checkstyle] [class]:0: Got an exception - java.lang.NoClassDefFoundError: com/onuspride/codetools/common/classpath/criteria/ClassNameCriteriaCollector
Im stumped. Ive checkd all the dependencies of my jar, they are all in the classpath, I don't understand how it can find one class file but not another in the same jar. Ive done all my dirty little tricks and I just don't get it.
any ideas?
You can do it like following :
Create plugin project and add your custom checks there.
Make appropriate changes to plugin.xml, checkstyle_packages.xml.
Export the project as Deployable Plug-ins and fragments (Export > Plug-in Developement)
Copy the jar file to Eclipse Plugin folde, so no need to install your custom check .
You can go through this tutorial for reference
To reduce effort, download a Sample Check, the file is here under the name net.sf.eclipsecs.sample
Just replace your source in src folder. Before replacing, refer this 3 files in src/net/sf/eclipsecs/sample/checks/ directory as you will need them in your com/onuspride/codetools/checkstyles/ directory :
checkstyle-metadata.properties
checkstyle-metadata.xml
messages.properties
After replacing the code, make appropriate changes in checkstyle_packages.xml file in src/ directory.
Extending Check is described nicely there.

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/"

copying a jar file in Apache Ant

I need to copy a jar file from one directory to another when my project is built. Placing the statement:
<copy file="${test.dir}/MyFirstTest.jar" todir="${share.path}"/>
works fine when the project is built alone, but if I clean and build the project I get a warning informing me that the ${test.dir}/ directory hasn't been created yet. If I'm understanding properly I should be able to create a 'target' and specify a dependency for this operation but I'm unsure of what dependency to specify. What series of statements do I need to use to ensure this copy will occur whether I clean and build or just build the project?
Please let me know if any further clarification is needed.
FYI I am using Netbeans 6.8 to build my project.
Assuming you have build, dist and javadoc folders do this in the clean.
<!-- Remove all output generated from this build script -->
<target name="clean" description="Clean project">
<delete dir="${build}" />
<delete dir="${dist}" />
<delete dir="${javadoc}" />
</target>
<!-- Initialize all elements needed for the Build -->
<target name="init">
<!-- Create the time stamp -->
<tstamp />
<!-- Create the build directory structure used by compile
and copy the deployment descriptors into it-->
<mkdir dir="${build}/classes" />
<mkdir dir="${dist}" />
<mkdir dir="${javadoc}" />
</target>
<!-- Write a target such as this -->
<target name="docopy" depends="init" description="do the copy">
<copy file="${test.dir}/MyFirstTest.jar" todir="${dist}"/>
</target>
When you run ant docopy It will run init first and then the docopy task.
You can create other tasks that have a depends="docopy" in it or move the copy file task to the init itself.
If I'm understanding properly I should be able to create a 'target' and specify a dependency for this operation but I'm unsure of what dependency to specify.
Well, either add a dependency to the target that actually creates ${share.path} if that makes sense or introduce a new target to create the directory if it doesn't exists. This is typically done is some kind of init target. Then, add the dependency like this:
<target name="copy-jar" depends="target-a, target-b">
<copy file="${test.dir}/MyFirstTest.jar" todir="${share.path}"/>
</target>
You could also simply try to create the directory before to copy the library:
<mkdir dir="${share.path}" failonerror="false">
<copy file="${test.dir}/MyFirstTest.jar" todir="${share.path}"/>