Skip to content
This repository was archived by the owner on Sep 17, 2020. It is now read-only.
This repository was archived by the owner on Sep 17, 2020. It is now read-only.

Not working in .NET Core v2.0 project #15

@eduherminio

Description

@eduherminio

I'm trying to create a .zip file using MSBuild following this example in a .csproj targetting netcoreapp2.0.

Since MSBuild on .NET Core does not support CodeTaskFactory, I tried modifying the task by using RoslynCodeTaskFactory in the following way:

<UsingTask TaskName="Zip" TaskFactory="CodeTaskFactory" AssemblyFile="$(RoslynCodeTaskFactory)">
    <ParameterGroup>
      <OutputFilename ParameterType="System.String" Required="true" />
      <Files ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
    </ParameterGroup>
    <Task>
      <Reference Include="System.IO.Compression" />
      <Using Namespace="System.IO.Compression" />
      <Code Type="Fragment" Language="cs">
        <![CDATA[
      try
      {
        using (Stream zipStream = new FileStream(Path.GetFullPath(OutputFilename), FileMode.Create, FileAccess.Write))
        using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create))
        {
            foreach (ITaskItem fileItem in Files)
            {
                string filename = fileItem.ItemSpec;
                using (Stream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
                using (Stream fileStreamInZip = archive.CreateEntry(new FileInfo(filename).Name).Open())
                    fileStream.CopyTo(fileStreamInZip);
            }
        }
        return true;
      }
      catch (Exception ex)
      {
        Log.LogErrorFromException(ex);
        return false;
      }
    ]]>
      </Code>
    </Task>
  </UsingTask>

However, I'm getting the following error:
The value "" resulting from evaluating the value of "$(RoslynCodeTaskFactory)" from attribute "AssemblyFile" of element <UsingTask> is not valid.

Am i doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions