<target name="write-head-part"> <echo file="${dynafile.path}\${dynafilename}"><?xml version="1.0" encoding="UTF-8"?> <project name="dyna-fxcop-build" default="run-fx-cop-report-creation" basedir="."> <target name="run-fx-cop-report-creation"> <exec executable="${fxcop.path}\FxCopCmd.exe" failonerror="false"></echo> </target>
${dynafile.path}\${dynafilename}
, using < >
< >
, to escape < >
characters. As well as, the exec
task is written to transfer the required parameters to the FxCop application. In this way, passing parameters, using arg
, you can solve the problem of a long list of paths to the analyzed files. <target name="create-arguments"> // <echo message="${item.file}"/> // , filename <basename property="filename" file="${item.file}"/> // output.path <OutputPath> csproj <loadfile srcfile="${item.file}" property="output.path"> <filterchain> <linecontains> <contains value="<OutputPath>"/> </linecontains> </filterchain> </loadfile> // <OutputType> csproj output.type <loadfile srcfile="${item.file}" property="output.type"> <filterchain> <linecontains> <contains value="<OutputType>"/> </linecontains> </filterchain> </loadfile> // <AssemblyName> csproj assembly.name <loadfile srcfile="${item.file}" property="assembly.name"> <filterchain> <linecontains> <contains value="<AssemblyName>"/> </linecontains> </filterchain> </loadfile> // OutputPath output.path.info <propertyregex property="output.path.info" input="${output.path}" regexp="<OutputPath>(.*?)</OutputPath>" select="\1" /> // OutputType output.type.info <propertyregex property="output.type.info" input="${output.type}" regexp="<OutputType>(.*?)</OutputType>" select="\1" /> // AssemblyName assembly.name.info <propertyregex property="assembly.name.info" input="${assembly.name}" regexp="<AssemblyName>(.*?)</AssemblyName>" select="\1" /> // <propertyregex property="item.path" input="${item.file}" regexp="(.*)\\" select="\1" /> <echo message="output.type.info = ${output.type.info}"/> <echo message="output.path = ${output.path}"/> // output.type.info <if> <contains string="WinExe" substring="${output.type.info}"/> <then> <property name="file.name.ext" value="${assembly.name.info}.exe"/> </then> <elseif> <contains string="Exe" substring="${output.type.info}"/> <then> <property name="file.name.ext" value="${assembly.name.info}.exe"/> </then> </elseif> <else> <property name="file.name.ext" value="${assembly.name.info}.dll"/> </else> </if> // <arg value=""/> value . <echo file="${dynafile.path}\${dynafilename}" append="true"> <arg value="/f:${item.path}\${output.path.info}${file.name.ext}"/> </echo> </target>
<target name="write-footer-part"> <echo file="${dynafile.path}\${dynafilename}" append="true"> <arg value="/r:${fxcop.path}\Rules"/> <arg value="/o:${fxcop.report.full.path}"/> </exec> </target> </project></echo> </target>
/r:${fxcop.path}\Rules
rules rules and the output folder for the report / /o:${fxcop.report.full.path}
. The closing tags for exec
, traget
and project
also traget
. <target name="run-fxcop"> // - <antcall target="write-head-part"/> // <echo file="${dynafile.path}\${dynafilename}" append="true"> </echo> <var name="dll.names" value=""/> // csproj , , item.file, // create-arguments <foreach target="create-arguments" param="item.file" inheritall="true"> <fileset dir="${basedir}" casesensitive="no"> <include name="**/*.csproj"/> // /obj/Debug/ <exclude name="**/obj/Debug/**.*"/> </fileset> </foreach> // - <antcall target="write-footer-part"/> // -. <subant target="run-fx-cop-report-creation"> <fileset dir="${dynafile.path}" includes="${dynafilename}"/> </subant> </target>
${dynafile.path}\${dynafilename}
. Next, the file is transferred to the mode of adding data to the end, using the echo command with the parameter append="true"
.csproj
, with the extension csproj
using foreach
. At the same time, the path to the file is written to the variable item.file, which is defined by param="item.file"
. Well and in order that ant did not view the contents of obj / Debug, using the instruction />
, we bring it to ignore.write-footer-part
, the final part of the dynamically generated build file is written.run-fx-cop-report-creation
, now we can accomplish it, using the subant task . In the parameters to the subant, specifying the path to the dynamically formed build-plan file, from which the run-fx-cop-report-creation
task will be executed. <?xml version="1.0" encoding="UTF-8"?> <project name="fxcop-xxx-project" default="run-fxcop" basedir="."> <property name="dynafile.path" value="${basedir}"/> <property name="dynafilename" value="dynabuild.xml"/> <property name="fxcop.report.dir" value="${basedir}\FxCopReports"/> <property name="fxcop.report.full.path" value="${fxcop.report.dir}\fxcop.report.xml"/> <target name="clean-fxcop-result-folder"> <echo message="Cleaning FxCop result report dir, and dynamic xml"/> <delete> <fileset dir="${fxcop.report.dir}" includes="**/*.*"/> </delete> <delete file="${dynafile.path}\${dynafilename}" failonerror="false"/> </target> <target name="run-fxcop"> <antcall target="write-head-part"/> <echo file="${dynafile.path}\${dynafilename}" append="true"> </echo> <var name="dll.names" value=""/> <foreach target="create-arguments" param="item.file" inheritall="true"> <fileset dir="${basedir}" casesensitive="no"> <include name="**/*.csproj"/> <exclude name="**/obj/Debug/**.*"/> </fileset> </foreach> <antcall target="write-footer-part"/> <subant target="run-fx-cop-report-creation"> <fileset dir="${dynafile.path}" includes="${dynafilename}"/> </subant> </target> <target name="create-arguments"> <echo message="${item.file}"/> <basename property="filename" file="${item.file}"/> <loadfile srcfile="${item.file}" property="output.path"> <filterchain> <linecontains> <contains value="<OutputPath>"/> </linecontains> </filterchain> </loadfile> <loadfile srcfile="${item.file}" property="output.type"> <filterchain> <linecontains> <contains value="<OutputType>"/> </linecontains> </filterchain> </loadfile> <loadfile srcfile="${item.file}" property="assembly.name"> <filterchain> <linecontains> <contains value="<AssemblyName>"/> </linecontains> </filterchain> </loadfile> <propertyregex property="output.path.info" input="${output.path}" regexp="<OutputPath>(.*?)</OutputPath>" select="\1" /> <propertyregex property="output.type.info" input="${output.type}" regexp="<OutputType>(.*?)</OutputType>" select="\1" /> <propertyregex property="assembly.name.info" input="${assembly.name}" regexp="<AssemblyName>(.*?)</AssemblyName>" select="\1" /> <propertyregex property="item.path" input="${item.file}" regexp="(.*)\\" select="\1" /> <echo message="output.type.info = ${output.type.info}"/> <echo message="output.path = ${output.path}"/> <if> <contains string="WinExe" substring="${output.type.info}"/> <then> <property name="file.name.ext" value="${assembly.name.info}.exe"/> </then> <elseif> <contains string="Exe" substring="${output.type.info}"/> <then> <property name="file.name.ext" value="${assembly.name.info}.exe"/> </then> </elseif> <else> <property name="file.name.ext" value="${assembly.name.info}.dll"/> </else> </if> <echo file="${dynafile.path}\${dynafilename}" append="true"> <arg value="/f:${item.path}\${output.path.info}${file.name.ext}"/> </echo> </target> <target name="write-head-part"> <echo file="${dynafile.path}\${dynafilename}"><?xml version="1.0" encoding="UTF-8"?> <project name="dyna-fxcop-build" default="run-fx-cop-report-creation" basedir="."> <target name="run-fx-cop-report-creation"> <exec executable="${fxcop.path}\FxCopCmd.exe" failonerror="false"></echo> </target> <target name="write-footer-part"> <echo file="${dynafile.path}\${dynafilename}" append="true"> <arg value="/r:${fxcop.path}\Rules"/> <arg value="/o:${fxcop.report.full.path}"/> </exec> </target> </project></echo> </target> </project>
Source: https://habr.com/ru/post/149406/
All Articles