6

I have the following inline task defined in a .csproj file that should run BeforeBuild.

<UsingTask TaskName="VersioningTask" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
    <FileName ParameterType="System.String" Required="true" />
    <XmlFileName ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
    <Reference Include="System.Xml.dll" />
    <Reference Include="System.Xml.Linq.dll"/>
    <Using Namespace="System" />
    <Using Namespace="System.IO" />
    <Using Namespace="System.Linq" />
    <Using Namespace="System.Text" />
    <Using Namespace="System.Text.RegularExpressions" />
    <Using Namespace="System.Xml.Linq" />
    <Code Type="Fragment" Language="cs"><![CDATA[
        var xDoc = XDocument.Load(XmlFileName);
        //...

When building the project from VS2012 I get the following error:

Could not find reference "System.Xml.dll". If this reference is required by your code, you may get compilation errors.

Could not find reference "System.Xml.Linq.dll". If this reference is required by your code, you may get compilation errors.

If I remove the XML stuff and the two references, the build succeeds. I have tried to use full paths to the DLL's (%windir%/assembly) without any success.

Any ideas whats wrong here are highly appreciated.

Community
  • 1
  • 1
Jay
  • 2,141
  • 6
  • 26
  • 37

3 Answers3

13

I had the same exact problem when referencing System.Xml.Linq. Switching to a compiled task does solve your solution, but to implement the original code as an Inline Task, simply drop the file extension from the references then your inline task so that you reference the root namespace rather than the file name.

Change this:

<Reference Include="System.Xml.dll" />
<Reference Include="System.Xml.Linq.dll"/>

To read:

<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq"/>
Nicodemeus
  • 4,005
  • 20
  • 23
  • 5
    Thanks, the MSDN page on inline tasks (http://msdn.microsoft.com/en-us/library/dd722601.aspx) incorrectly includes the .dll at the end. – makhdumi Apr 30 '14 at 23:50
1

For the unlucky souls that stumbled on the problem of MSBuild inline task Reference and Using:

Change my task to a compiled task would require me to upgrade my framework from .Net6 to .Net7, since 6 doesn't have the build package. Sadly, I don't want to go through with that.

What I tried useful is that, if you tested your code working in a cs file, try interchanging Using and Reference, or maybe use both, like the above question has done.

For example, just

<Using Namespace="System.IO.Compression" />

alone doesn't work. I had to also add

<Reference Include="System.IO.Compression" />

and for the static member if you are using any, you gotta add a reference to the exact package like this:

<Reference Include="System.IO.Compression.FileSystem" />

I was using ZipFile.Open in my task. (Surprisingly, this reference recommendation was from the log error I got after I run the build, can you believe that?!)

I'm not clear what the rules are about Reference and Using. As for now, I'm trying the three options, just Reference or just Using or Both of the same packge, until one of them works.

If anyone finds the doc about Reference and Using. Please leave it in a comment. Preferably, from the official MS doc. Out of all the official docs from difference corporations I read so far, MS is one of the better ones.

Luyang Du
  • 160
  • 1
  • 10
-3

Solved it by using regular tasks instead of using inline tasks.

Jay
  • 2,141
  • 6
  • 26
  • 37