VSTest#2 Task is Updating / Overriding coverlet.runsettings and not respecting exclusions - azure-devops

I am trying to add code coverage to a .NET Framework 4.8 solution in Azure DevOps. I have based my approach on the questions here and here and the coverlet docs, and am successfully getting code coverage results.
However this solution also contains a number of shared projects which have their unit tests in a different solution. I wish to exclude these projects, and the test projects themselves from the coverage report.
In my coverlet.runsettings file I have included the following lines based on the docs:
<Exclude>[coverlet.*.tests?]*,[*]Coverlet.Core*,[Company.*UnitTest]*</Exclude>
<Include>[Company.Application.*]*</Include>
However when the tests are run using the VSTest#2 I see the following in the logs
Provided settings file:
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>cobertura</Format>
<Exclude>[coverlet.*.tests?]*,[*]Coverlet.Core*,[Company.*UnitTests]*</Exclude>
<Include>[Company.Application.*]*</Include>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
Updated Run Settings:
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<!-- As above -->
</DataCollector>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<!-- Lots of configuration ommitted for brevity -->
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
<RunConfiguration>
<MaxCpuCount>0</MaxCpuCount>
<BatchSize>1000</BatchSize>
<ResultsDirectory>D:\a\_temp\TestResults</ResultsDirectory>
</RunConfiguration>
</RunSettings>
**************** Starting test execution *********************
So it appears the VS test task is altering my runsettings on the fly and then not respecting the inclusions and exclusions values
My yaml is:
- task: VSTest#2
displayName: 'Run Tests'
inputs:
testAssemblyVer2: '**\*UnitTests*.dll'
searchFolder: '.\Output'
codeCoverageEnabled: true
runSettingsFile: .\Builds\coverlet.runsettings
Can anyone suggest a setting or some other way to respect the inclusions and exclusions?

It is counterintuitive, but in order to VS test task does not alter runsettings on the fly, need to remove "codeCoverageEnabled: true" and add "runSettingsFile: .\Builds\coverlet.runsettings":
- task: VSTest#2
displayName: 'Run Tests'
inputs:
testAssemblyVer2: '**\*UnitTests*.dll'
searchFolder: '.\Output'
runSettingsFile: .\Builds\coverlet.runsettings
Code coverage still will be calculated because of runsettings file.
In order to exclude something, you can check https://learn.microsoft.com/en-us/visualstudio/test/customizing-code-coverage-analysis?view=vs-2022#sample-runsettings-file
I copy pasted here in case the link is broken
<!--
About include/exclude lists:
Empty "Include" clauses imply all; empty "Exclude" clauses imply none.
Each element in the list is a regular expression (ECMAScript syntax). See /visualstudio/ide/using-regular-expressions-in-visual-studio.
An item must first match at least one entry in the include list to be included.
Included items must then not match any entries in the exclude list to remain included.
-->
<!-- Match assembly file paths: -->
<ModulePaths>
<Include>
<ModulePath>.*\.dll$</ModulePath>
<ModulePath>.*\.exe$</ModulePath>
</Include>
<Exclude>
<ModulePath>.*CPPUnitTestFramework.*</ModulePath>
</Exclude>
</ModulePaths>
<!-- Match fully qualified names of functions: -->
<!-- (Use "\." to delimit namespaces in C# or Visual Basic, "::" in C++.) -->
<Functions>
<Exclude>
<Function>^Fabrikam\.UnitTest\..*</Function>
<Function>^std::.*</Function>
<Function>^ATL::.*</Function>
<Function>.*::__GetTestMethodInfo.*</Function>
<Function>^Microsoft::VisualStudio::CppCodeCoverageFramework::.*</Function>
<Function>^Microsoft::VisualStudio::CppUnitTestFramework::.*</Function>
</Exclude>
</Functions>
<!-- Match attributes on any code element: -->
<Attributes>
<Exclude>
<!-- Don't forget "Attribute" at the end of the name -->
<Attribute>^System\.Diagnostics\.DebuggerHiddenAttribute$</Attribute>
<Attribute>^System\.Diagnostics\.DebuggerNonUserCodeAttribute$</Attribute>
<Attribute>^System\.CodeDom\.Compiler\.GeneratedCodeAttribute$</Attribute>
<Attribute>^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$</Attribute>
</Exclude>
</Attributes>
<!-- Match the path of the source files in which each method is defined: -->
<Sources>
<Exclude>
<Source>.*\\atlmfc\\.*</Source>
<Source>.*\\vctools\\.*</Source>
<Source>.*\\public\\sdk\\.*</Source>
<Source>.*\\microsoft sdks\\.*</Source>
<Source>.*\\vc\\include\\.*</Source>
</Exclude>
</Sources>
<!-- Match the company name property in the assembly: -->
<CompanyNames>
<Exclude>
<CompanyName>.*microsoft.*</CompanyName>
</Exclude>
</CompanyNames>
<!-- Match the public key token of a signed assembly: -->
<PublicKeyTokens>
<!-- Exclude Visual Studio extensions: -->
<Exclude>
<PublicKeyToken>^B77A5C561934E089$</PublicKeyToken>
<PublicKeyToken>^B03F5F7F11D50A3A$</PublicKeyToken>
<PublicKeyToken>^31BF3856AD364E35$</PublicKeyToken>
<PublicKeyToken>^89845DCD8080CC91$</PublicKeyToken>
<PublicKeyToken>^71E9BCE111E9429C$</PublicKeyToken>
<PublicKeyToken>^8F50407C4E9E73B6$</PublicKeyToken>
<PublicKeyToken>^E361AF139669C375$</PublicKeyToken>
</Exclude>
</PublicKeyTokens>

Related

Azure pipeline transforming web.config files during release

I'm trying to use web.config transformation in my release pipeline. However, no matter what I'm doing, I always get
2019-11-11T12:19:46.1172474Z ##[warning]Unable to apply transformation for the given package. Verify the following.
I have a Web.config and a Web.Elastic.config. The project has no dependentUpon for any .config files in it's csproj, and Web.Elastic.config has content as build action and is in the zip file generated from the build task.
In addition, I disabled config transformations during building just to be sure. I'm not sure what else I can do. This happens both when using the File Transform Task Preview as well as the XML transformation option during the IIS Web App Deploy task.
The File Transform task is configured like this:
I reduced my configs to this to see if there's something wrong with the transformation itself:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="apiConfig" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<apiConfig>
<add key="ClientBasetUrl" value="http://localhost:4200" />
</apiConfig>
<system.web>
<compilation debug="true" targetFramework="4.6.2">
<assemblies>
<add assembly="System.Net.Http.WebRequest, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
<!-- This will handle requests up to 20MB -->
<httpRuntime targetFramework="4.6.1" maxRequestLength="20480" />
</system.web>
</configuration>
with the transformation looking like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<apiConfig xdt:Transform="Replace">
<add key="ClientBasetUrl" value="https://elastic.OURPROJECT.com" />
</apiConfig>
<system.web xdt:Transform="Replace">
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.6.2" />
<httpRuntime targetFramework="4.6.1" maxRequestLength="20480" />
</system.web>
</configuration>
With System.Debug set to true, the File Transformation task provides the following logs, which are not very helpful:
2019-11-11T12:19:43.1224281Z ##[debug]agent.TempDirectory=C:\vstsagent\A1\_work\_temp
2019-11-11T12:19:43.1289319Z ##[debug]loading inputs and endpoints
2019-11-11T12:19:43.1292645Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2019-11-11T12:19:43.1301246Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2019-11-11T12:19:43.1304962Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2019-11-11T12:19:43.1307442Z ##[debug]loading INPUT_ENABLEXMLTRANSFORM
2019-11-11T12:19:43.1309334Z ##[debug]loading INPUT_FILETYPE
2019-11-11T12:19:43.1316311Z ##[debug]loading INPUT_FOLDERPATH
2019-11-11T12:19:43.1316632Z ##[debug]loading INPUT_XMLTRANSFORMATIONRULES
2019-11-11T12:19:43.1322390Z ##[debug]loaded 7
2019-11-11T12:19:43.1334690Z ##[debug]Agent.ProxyUrl=undefined
2019-11-11T12:19:43.1336439Z ##[debug]Agent.CAInfo=undefined
2019-11-11T12:19:43.1336699Z ##[debug]Agent.ClientCert=undefined
2019-11-11T12:19:43.1336884Z ##[debug]Agent.SkipCertValidation=undefined
2019-11-11T12:19:43.2867243Z ##[debug]check path : C:\vstsagent\A1\_work\_tasks\FileTransform_8ce97e91-56cc-4743-bfab-9a9315be5f27\1.1.6\task.json
2019-11-11T12:19:43.2867893Z ##[debug]adding resource file: C:\vstsagent\A1\_work\_tasks\FileTransform_8ce97e91-56cc-4743-bfab-9a9315be5f27\1.1.6\task.json
2019-11-11T12:19:43.2868317Z ##[debug]system.culture=en-US
2019-11-11T12:19:43.2882674Z ##[debug]check path : C:\vstsagent\A1\_work\_tasks\FileTransform_8ce97e91-56cc-4743-bfab-9a9315be5f27\1.1.6\node_modules\webdeployment-common-v2\module.json
2019-11-11T12:19:43.2883957Z ##[debug]adding resource file: C:\vstsagent\A1\_work\_tasks\FileTransform_8ce97e91-56cc-4743-bfab-9a9315be5f27\1.1.6\node_modules\webdeployment-common-v2\module.json
2019-11-11T12:19:43.2884521Z ##[debug]system.culture=en-US
2019-11-11T12:19:43.2900694Z ##[debug]folderPath=C:\vstsagent\A1\_work\r2\a\SLX-Backend\drop\OURPROJECT.zip
2019-11-11T12:19:43.2902832Z ##[debug]Finding files matching input: C:\vstsagent\A1\_work\r2\a\SLX-Backend\drop\OURPROJECT.zip
2019-11-11T12:19:43.2907625Z ##[debug]fileType=xml
2019-11-11T12:19:43.2908713Z ##[debug]targetFiles=null
2019-11-11T12:19:43.2911002Z ##[debug]enableXmlTransform=true
2019-11-11T12:19:43.2912768Z ##[debug]xmlTransformationRules=-transform **\OURPROJECT\obj\Release\Package\PackageTmp\Web.Elastic.config -xml **\OURPROJECT\obj\Release\Package\PackageTmp\Web.config
2019-11-11T12:19:43.2916829Z ##[debug]This is zip package
2019-11-11T12:19:43.2919443Z ##[debug]Agent.TempDirectory=C:\vstsagent\A1\_work\_temp
2019-11-11T12:19:43.2919672Z ##[debug]Agent.TempDirectory=C:\vstsagent\A1\_work\_temp
2019-11-11T12:19:43.2927405Z ##[debug]extracting C:\vstsagent\A1\_work\r2\a\SLX-Backend\drop\OURPROJECT.zip to C:\vstsagent\A1\_work\_temp\temp_web_package_9699193652416063
2019-11-11T12:19:45.9624316Z ##[debug]extracted C:\vstsagent\A1\_work\r2\a\SLX-Backend\drop\OURPROJECT.zip to C:\vstsagent\A1\_work\_temp\temp_web_package_9699193652416063 Successfully
2019-11-11T12:19:46.0225418Z ##[debug]defaultRoot: 'C:\vstsagent\A1\_work\_temp\temp_web_package_9699193652416063'
2019-11-11T12:19:46.0225668Z ##[debug]findOptions.allowBrokenSymbolicLinks: 'false'
2019-11-11T12:19:46.0225791Z ##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
2019-11-11T12:19:46.0225928Z ##[debug]findOptions.followSymbolicLinks: 'true'
2019-11-11T12:19:46.0226038Z ##[debug]matchOptions.debug: 'false'
2019-11-11T12:19:46.0226147Z ##[debug]matchOptions.nobrace: 'true'
2019-11-11T12:19:46.0226280Z ##[debug]matchOptions.noglobstar: 'false'
2019-11-11T12:19:46.0226387Z ##[debug]matchOptions.dot: 'true'
2019-11-11T12:19:46.0226547Z ##[debug]matchOptions.noext: 'false'
2019-11-11T12:19:46.0226657Z ##[debug]matchOptions.nocase: 'true'
2019-11-11T12:19:46.0226763Z ##[debug]matchOptions.nonull: 'false'
2019-11-11T12:19:46.0226896Z ##[debug]matchOptions.matchBase: 'false'
2019-11-11T12:19:46.0227016Z ##[debug]matchOptions.nocomment: 'false'
2019-11-11T12:19:46.0227146Z ##[debug]matchOptions.nonegate: 'false'
2019-11-11T12:19:46.0227252Z ##[debug]matchOptions.flipNegate: 'false'
2019-11-11T12:19:46.0227392Z ##[debug]pattern: '**\OURPROJECT\obj\Release\Package\PackageTmp\Web.config'
2019-11-11T12:19:46.0227519Z ##[debug]findPath: 'C:\vstsagent\A1\_work\_temp\temp_web_package_9699193652416063'
2019-11-11T12:19:46.0227632Z ##[debug]statOnly: 'false'
2019-11-11T12:19:46.0227769Z ##[debug]findPath: 'C:\vstsagent\A1\_work\_temp\temp_web_package_9699193652416063'
2019-11-11T12:19:46.0227885Z ##[debug]findOptions.allowBrokenSymbolicLinks: 'false'
2019-11-11T12:19:46.0228032Z ##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
2019-11-11T12:19:46.0228152Z ##[debug]findOptions.followSymbolicLinks: 'true'
...
2019-11-11T12:19:46.0970036Z ##[debug]615 results
2019-11-11T12:19:46.0970193Z ##[debug]found 615 paths
2019-11-11T12:19:46.0970374Z ##[debug]applying include pattern
2019-11-11T12:19:46.0970559Z ##[debug]adjustedPattern: 'C:\vstsagent\A1\_work\_temp\temp_web_package_9699193652416063\**\PackageTmp\Web.config'
2019-11-11T12:19:46.1099930Z ##[debug]1 matches
2019-11-11T12:19:46.1100207Z ##[debug]1 final results
2019-11-11T12:19:46.1172474Z ##[warning]Unable to apply transformation for the given package. Verify the following.
2019-11-11T12:19:46.1179673Z ##[debug]Processed: ##vso[task.issue type=warning;]Unable to apply transformation for the given package. Verify the following.
As the configuration in the config files you shared above, there's no any problem in it when apply it on my side.
In fact, in your build log, it has been show you the problem caused by what.
You can see that the task only found out only one file while here it should match 2 files, like this:
These 2 files, one is config and another is transformation config file. But in your build, it can only found out one file (Not sure whether the log you shared is completed, as I see, it only detect out Web.config file).
This issue should relevant the configuration of your task. Seems you were linking the artifact, and want to applying the transformation into that.
Please modify the Package or folder blank as this pic shown:
And change your Transformation rules as:
-transform **\*.Elastic.config -xml **\*.config

"Function was not implemented" when trying to use ONI recording

I'm trying to use an oni recording in my application using OpenNI. Here is my xml file:
<OpenNI>
<Licenses>
<!-- Add application-specific licenses here
<License vendor="vendor" key="key"/>
-->
</Licenses>
<Log writeToConsole="false" writeToFile="false">
<!-- 0 - Verbose, 1 - Info, 2 - Warning, 3 - Error (default) -->
<LogLevel value="3"/>
<Masks>
<Mask name="ALL" on="true"/>
</Masks>
<Dumps>
</Dumps>
</Log>
<ProductionNodes>
<Recording file="Recording.oni" />
<!-- Set global mirror -->
<GlobalMirror on="true"/>
</ProductionNodes>
</OpenNI>
Everything looks ok, but when I try to run my program, I get:
Open failed: Function was not implemented!
What could be the problem?
The problem were the two following lines:
<!-- Set global mirror -->
<GlobalMirror on="true"/>
After removing them, my program works fine.

Namespace/Mymodule/Block/Item.php file code not accessible on frontend after adding through xml

i am working on a module e.g "Mymodule", in which i need to filter the results. i.e. for Partners i created Partner.php and for Community i created Community.php in
Mymodule/Block/Partner.php
Mymodule/Block/Community.php
Now i wanted to access their code in frontend through Mymodule.XML
<block type="mymodule/partner" ......................... />
but this doesn't work on LIVE SERVER, although it does work on local Wamp server :( ... Any idea ?
Although when i access the default Mymodule.php code in the same and add the code i placed in partner and community file, it does work.
Is there something i am missing ?
First, you have to define the blocks in your module's config.xml:
<config>
<global>
<blocks>
<mymodule>
<class>Namespace_Mymodule_Block</class>
</mymodule>
</blocks>
</global>
</config>
Second, you have to use the right block type in your layout XML:
<block type="mymodule/partner" ......................... />
You must not write ".php" in the block type. Note, that the term "mymodule" has to be the same in the config xml as well as in the block type.
Hope this helps!
I'm not strictly sure how your code would ever have worked. But assuming you haven't built a module before, you'll need a minimum of 3 files.
app/etc/modules/Sonassi_Module.xml
app/code/community/Sonassi/Module/etc/config.xml
app/code/community/Sonassi/Module/Block/Partner.php
In the first file ... app/etc/modules/Sonassi_Module.xml
<?xml version="1.0"?>
<config>
<modules>
<Sonassi_Module>
<active>true</active>
<codePool>community</codePool>
</Sonassi_Module>
</modules>
</config>
In the second file ... app/code/community/Sonassi/Module/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Sonassi_Module>
<version>0.1.0</version>
</Sonassi_Module>
</modules>
<frontend>
<routers>
<module>
<use>standard</use>
<args>
<module>Sonassi_Module</module>
<frontName>module</frontName>
</args>
</module>
</routers>
</frontend>
<global>
<blocks>
<module>
<class>Sonassi_Module_Block</class>
</module>
</blocks>
</global>
</config>
In the third file ... app/code/community/Sonassi/Module/Block/Partner.php
class Sonassi_Module_Block_Partner extends Core_Block_Template
{
}
Then finally, you can then use
<block type="module/partner" ......................... />

SYmfony plugin upload error: You must specify the min version for symfony

I have been trying to upload my SYmfony plugin for some time but I keep getting this error.
Initially the dependency on the SYmfony Package was missing, but I added that.
My package.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<package packagerversion="1.9.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
<name>sfActivateablePlugin</name>
<channel>pear.symfony-project.com</channel>
<summary>sfActivateablePlugin allows auditing record activation/deactivation by setting up a flag, timestamp & user detail fields.</summary>
<description>The sfActivateablePlugin allows you to automatically:
* create a `is_active` flag (or name of your choice)
* create timestamp & user detail fields (e.g. `activated_by`, `activated_at`, ...)
* populate timestamps & user details when `is_active` flag is toggled on a record.</description>
<lead>
<name>Prasad Gupte</name>
<user>prasadgupte</user>
<email>xxxxxxxx#gmail.com</email>
<active>yes</active>
</lead>
<date>2010-09-22</date>
<time>19:33:09</time>
<version>
<release>1.0.0</release>
<api>1.0.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.symfony-project.com/license">MIT license</license>
<notes>
* First public release.
</notes>
<contents>
<dir baseinstalldir="sfActivateablePlugin/" name="/">
<file baseinstalldir="sfActivateablePlugin/" md5sum="89b09d4d48e5259a3c659dfc65b0fc52" name="config/plugin_settings.yml.sample" role="data" />
<file baseinstalldir="sfActivateablePlugin/" md5sum="8b40522acb23552e6e31ba2416387515" name="lib/Activateable.class.php" role="php" />
<file baseinstalldir="sfActivateablePlugin/" md5sum="926a9eb938eccc9083d2b116e50246b3" name="lib/Listener/Activateable.class.php" role="php" />
<file baseinstalldir="sfActivateablePlugin/" md5sum="17346d33da2ea3b9d880afc71e7022fd" name="LICENSE" role="doc" />
<file baseinstalldir="sfActivateablePlugin/" md5sum="b836dfd2f324ae4ea975842197dcf8e2" name="README" role="doc" />
</dir>
</contents>
<dependencies>
<required>
<php>
<min>5.2.6</min>
</php>
<pearinstaller>
<min>1.4.1</min>
</pearinstaller>
<package>
<name>Symfony</name>
<channel>pear.symfony-project.org</channel>
<min>1.4</min>
<recommended>1.4</recommended>
</package>
</required>
</dependencies>
<phprelease />
<changelog>
<release>
<version>
<release>1.0.0</release>
<api>1.0.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2010-09-22</date>
<license uri="http://www.symfony-project.com/license">MIT license</license>
<notes>
* First public release.
</notes>
</release>
</changelog>
</package>
Am I missing some tag? Or specified incorrect Symfony version? Pl help
Figured out a couple of mistakes:
1. the package name is symfony and not Symfony
2. the max version is also required
If you use the Pear Package Manager API:
$packagexml->addPackageDepWithChannel('required', 'symfony', 'pear.symfony-project.com', '1.4', '1.4', '1.4');

MSBuild ReadLinesFromFile all text on one line

When I do a ReadLinesFromFile on a file in MSBUILD and go to output that file again, I get all the text on one line. All the Carriage returns and LineFeeds are stripped out.
<Project DefaultTargets = "Deploy"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<ItemGroup>
<MyTextFile Include="$(ReleaseNotesDir)$(NewBuildNumber).txt"/>
</ItemGroup>
<Target Name="ReadReleaseNotes">
<ReadLinesFromFile
File="#(MyTextFile)" >
<Output
TaskParameter="Lines"
ItemName="ReleaseNoteItems"/>
</ReadLinesFromFile>
</Target>
<Target Name="MailUsers" DependsOnTargets="ReadReleaseNotes" >
<Mail SmtpServer="$(MailServer)"
To="$(MyEMail)"
From="$(MyEMail)"
Subject="Test Mail Task"
Body="#(ReleaseNoteItems)" />
</Target>
<Target Name="Deploy">
<CallTarget Targets="MailUsers" />
</Target>
</Project>
I get the text from the file which normally looks like this
- New Deployment Tool for BLAH
- Random other stuff()""
Coming out like this
- New Deployment Tool for BLAH;- Random other stuff()""
I know that the code for ReadLinesFromFile will pull the data in one line at a time and strip out the carriage returns.
Is there a way to put them back in?
So my e-mail looks all nicely formatted?
Thanks
The problem here is you are using the ReadLinesFromFile task in a manner it wasn't intended.
ReadLinesFromFile Task
Reads a list of items from a text file.
So it's not just reading all the text from a file, it's reading individual items from a file and returning an item group of ITaskItems. Whenever you output a list of items using the #() syntax you will get a separated list, the default of which is a semicolon. This example illustrates this behavior:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<ItemGroup>
<Color Include="Red" />
<Color Include="Blue" />
<Color Include="Green" />
</ItemGroup>
<Target Name="Build">
<Message Text="ItemGroup Color: #(Color)" />
</Target>
</Project>
And the output looks like this:
ItemGroup Color: Red;Blue;Green
So while the best solution to your problem is to write an MSBuild task that reads a file into a property as a string an not a list of items, that's really not what you asked for. You asked if there was a way to put them back, and there is using MSBuild Transforms.
Transforms are used to create one list from another and also have the ability to transform using a custom separator. So the answer is to transform your list read in using ReadItemsFromFile into another list with newlines. Here is an example that does just that:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<ItemGroup>
<File Include="$(MSBuildProjectDirectory)\Test.txt" />
</ItemGroup>
<Target Name="Build">
<ReadLinesFromFile File="#(File)">
<Output TaskParameter="Lines" ItemName="FileContents" />
</ReadLinesFromFile>
<Message Text="FileContents: #(FileContents)" />
<Message Text="FileContents Transformed: #(FileContents->'%(Identity)', '%0a%0d')" />
</Target>
</Project>
Test.text looks like:
Red
Green
Blue
And the output looks like this:
[C:\temp]:: msbuild test.proj
Microsoft (R) Build Engine Version 3.5.21022.8
[Microsoft .NET Framework, Version 2.0.50727.1433]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 11/8/2008 8:16:59 AM.
Project "C:\temp\test.proj" on node 0 (default targets).
FileContents: Red;Green;Blue
FileContents Transformed: Red
Green
Blue
Done Building Project "C:\temp\test.proj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.03
What's going on here is two things.
#(FileContents->'%(Identity)', '%0a%0d')
We are transforming the list from one type to another using the same values (Identity) but a custom separator '%0a%0d'
We are using MSBuild Escaping to escape the line feed (%0a) and carriage return (%0d)
If you are using MSBuild 4.0, you can do the following instead, to get the contents of a file:
$([System.IO.File]::ReadAllText($FilePath))
Instead of #(FileContents->'%(Identity)', '%0a%0d') I believe you can do #(FileContents, '%0a%0d')
You can use WriteLinesToFile combined with
$([System.IO.File]::ReadAllText($(SourceFilePath))):
< WriteLinesToFile File="$(DestinationFilePath)" Lines="$([System.IO.File]::ReadAllText($(SourceFilePath)))"
Overwrite="true"
/>
This will copy your file exactly at it is.