L. Piotrowski
L. Piotrowski

Reputation: 1579

Publishing with Visual Studio 2017 MVC ASP.NET Core "They must have the same number of items"

I get the following message when I try and Publish:

Severity Code Description Project File Line Suppression State

Error "DestinationFiles" refers to 1 item(s), and "SourceFiles" refers to 2 item(s). They must have the same number of items.

I have my project working on my localhost and I am now looking to publish...but I get the above error. I converted my project from VS 2015 and Publishing was working fine. Just to make sure my old Publishing Profile wasn't the issue , I deleted my old working copy of my Profile and set up a new one. I know that VS 2017 was just released a couple of days ago, any help would be great.

Upvotes: 6

Views: 1793

Answers (3)

Velyo
Velyo

Reputation: 280

That bug was fixed in latest dotnet core sdk, in my case it is the latest 1.0.0-rc4-004578.
Unfortunately in the new releases they decided that .csproj file don't need even the default compile and resources patterns in it, which will be included by default by msbuild tasks.
Thus if they are included in your .csproj file you wont be able to compile with rc4.

So here are the steps/changes which done the job for me:

  • download and install dotnet sdk rc4 or above from [https://github.com/dotnet/cli]
  • add to to you solution/project folder global.json with targeting the new dotnet core, in my case: { "sdk": { "version": "1.0.0-rc4-004578" } }
  • open you .csproj file and edit it (you can now directly in VS 2017); add debug configuration condition to default patterns items group

    <ItemGroup Condition=" '$(Configuration)' == 'Debug' "> <Compile Include="**\*.cs" /> <EmbeddedResource Include="**\*.resx" /> </ItemGroup>

  • ensure you are using the right(new) dotnet sdk:

    dotnet --versoin

  • publish you porject with configuration setting Release

    dotnet publish PATH\MyPorject.csproj -c Release -o OUT_DIR

Note we kept the section with default compile patterns in .csproj file but with debug config condition, that's needed, if you would like to keep you projects compile and running in VS 2017 RC, which is using dotnet sdk preview4.
Just have in mind your active configuration in there should Debug.

You can find some more details about the problem discussed here under dotnet team thread at [https://github.com/dotnet/cli/issues/4759#issuecomment-274904448]

Upvotes: 0

toralux
toralux

Reputation: 518

This is a known bug and is mentioned in the VS2017 RC Tooling Known Issues document:

Unable to publish

Unable to publish ASP.NET Core Web Application (.NET Framework)

  • Issue:

If you try to publish an ASP.NET Core Web Application (.NET Framework), you will run into the following error: "DestinationFiles" refers to 1 item(s), and "SourceFiles" refers to 2 item(s). They must have the same number of items

  • Workaround:

None available

https://github.com/aspnet/Tooling/blob/master/known-issues-vs2017.md

Look back later to see if a workaround is provided.

Editing "Microsoft.NET.Publish.targets" in folder "C:\Program Files\dotnet\sdk\1.0.0-preview4-004233\Sdks\Microsoft.NET.Sdk\build" didn't work for me though.

Upvotes: 3

Maarten
Maarten

Reputation: 1951

I think there is a bug in the Microsoft.NET.Publish.targets file.

I changed the DestinationFiles line (line 99 and 127) as below, and now it works

<Copy SourceFiles = "@(_ResolvedFileToPublishAlways)"
      DestinationFiles="@(_ResolvedFileToPublishAlways -> '$(PublishDir)%(RelativePath)')"
      OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
      Retries="$(CopyRetryCount)"
      RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
      UseHardlinksIfPossible="$(CreateHardLinksForPublishFilesIfPossible)"
      UseSymboliclinksIfPossible="$(CreateSymbolicLinksForPublishFilesIfPossible)">

Upvotes: 3

Related Questions