Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MSB4067 The element <WriteLinesToFile> beneath element <Target> is unrecognized

I have a Directory.Build.targets file that would increment build number of the project version when building with Release configuration. I.e., the product version is 1.0.0.0, when built in Release config, this target would make it 1.0.0.1, and so on. For some reason I’m getting this error:

MSB4067 The element <WriteLinesToFile> beneath element <Target> is unrecognized.

Code

<Project Sdk="Microsoft.NET.Sdk">
    <Target Name="IncrementBuildNumber" BeforeTargets="GenerateAssemblyInfo" Condition="'$(Configuration)' == 'Release'">
        <PropertyGroup>
            <VersionFile>$(MSBuildThisFileDirectory)version.txt</VersionFile>
        </PropertyGroup>

        <ReadLinesFromFile File="$(VersionFile)">
            <Output TaskParameter="Lines" ItemName="VersionLines"/>
        </ReadLinesFromFile>

        <PropertyGroup>
            <VersionString>%(VersionLines[0])</VersionString>
            <MajorVersion>$([System.String]::Split($(VersionString), '.')[0])</MajorVersion>
            <MinorVersion>$([System.String]::Split($(VersionString), '.')[1])</MinorVersion>
            <PatchNumber>$([System.String]::Split($(VersionString), '.')[2])</PatchNumber>
            <BuildNumber>$([System.String]::Split($(VersionString), '.')[3])</BuildNumber>
        </PropertyGroup>

        <PropertyGroup>
            <NewBuildNumber>$([System.Int32]::Parse($(BuildNumber)) + 1)</NewBuildNumber>
            <NewVersion>$(MajorVersion).$(MinorVersion).$(PatchNumber).$(NewBuildNumber)</NewVersion>
        </PropertyGroup>

        <WriteLinesToFile File="$(VersionFile)" Overwrite="true">
            $(NewVersion)
        </WriteLinesToFile>

        <PropertyGroup>
            <Version>$(NewVersion)</Version>
        </PropertyGroup>
    </Target>
</Project>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I think the content of the write operation needs to be passed as a Lines attribute rather than as the body. <WriteLinesToFile File="$(VersionFile)" Overwrite="true" Lines="$(NewVersion)" />

I used this as a reference https://learn.microsoft.com/en-us/visualstudio/msbuild/writelinestofile-task?view=vs-2022#example

This is a guess and I haven’t tested it!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading