jeffkl/RoslynCodeTaskFactory

Ref assemblies in the package are broken

smaillet opened this issue · 3 comments

The ref assemblies included in the ref folder of the package don't seem to work together correctly. (Version mismatches) In particular when building a task that uses Linq to XML I get the following warnings and errors:

Warning	CS1701	Assuming assembly reference 'System.Xml.ReaderWriter, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' used by 'System.Xml.XDocument' matches identity 'System.Xml.ReaderWriter, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' of 'System.Xml.ReaderWriter', you may need to supply runtime policy

So the version of System.Xml.Document has a reference to a newer version of System.Xml.ReaderWriter than what is included in the package. Which leads to an error at build time:

Error	MSB4018	The "XXX" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at InlineCode.ParseBuildVersionXml.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

There's an obvious version mismatch on the assemblies that the taskfactory and msbuild are not able to resolve. (Tried builds from VS and dotnet.exe so it isn't dependent on the runtime used for MSBuild)

Can you please share what your inline task looks like?

It's a pretty simple task to read an XML file containing build version information

    <UsingTask TaskName="ParseBuildVersionXml" TaskFactory="CodeTaskFactory" AssemblyFile="$(RoslynCodeTaskFactory)">
        <ParameterGroup>
            <BuildVersionXml Required="true"/>
            <BuildMajor Output="true"/>
            <BuildMinor Output="true"/>
            <BuildPatch Output="true"/>
            <PreReleaseName Output="true"/>
            <PreReleaseNumber Output="true"/>
            <PreReleaseFix Output="true"/>
        </ParameterGroup>
        <Task>
            <Reference Include="System.Xml.ReaderWriter"/>
            <Reference Include="System.Xml.XDocument"/>
            <Code Type="Fragment" Language="cs">
<![CDATA[
            using( var stream = File.OpenText( BuildVersionXml ) )
            {
                var xdoc = System.Xml.Linq.XDocument.Load( stream, System.Xml.Linq.LoadOptions.None );
                var data = xdoc.Element( "BuildVersionData" );

                foreach( var attrib in data.Attributes( ) )
                {
                    switch( attrib.Name.LocalName )
                    {
                    case "BuildMajor":
                        BuildMajor = attrib.Value;
                        break;

                    case "BuildMinor":
                        BuildMinor = attrib.Value;
                        break;

                    case "BuildPatch":
                        BuildPatch = attrib.Value;
                        break;

                    case "PreReleaseName":
                        PreReleaseName = attrib.Value;
                        break;

                    case "PreReleaseNumber":
                        PreReleaseNumber = attrib.Value;
                        break;

                    case "PreReleaseFix":
                        PreReleaseFix = attrib.Value;
                        break;
                    }
                }

                // correct malformed values
                if( string.IsNullOrWhiteSpace( PreReleaseName ) )
                {
                    PreReleaseNumber = "0";
                    PreReleaseFix = "0";
                }

                if( PreReleaseNumber == "0" )
                {
                    PreReleaseFix = "0";
                }
            }
]]>
            </Code>
        </Task>
    </UsingTask>

@smaillet Did you have a chance to try the new package to verify its fixed now?