Publishing with Visual Studio 2017 MVC ASP.NET Core "They Must Have The Same Number Of Elements"

I get the following message when I try to publish:

Severity code Description Project file line suppression status

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

I have my project working on my localhost and now I want to publish ... but I am getting the above error. I converted my project with VS 2015 and the publication worked fine. To make sure that my old publishing profile was not a problem, I deleted my old working copy of my profile and installed a new one. I know that VS 2017 was released just a couple of days ago, any help would be great.

+6
source share
3 answers

I think there is an error in the Microsoft.NET.Publish.targets file.

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

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

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

Unable to post

Unable to publish ASP.NET core web application (.NET Framework)

  • Question:

If you try to publish the main ASP.NET web application (.NET Framework), you will encounter the following error: "DestinationFiles" refers to 1 item (s), and "SourceFiles" refers to 2 items. They must have the same number of items.

  • Workaround:

No available

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

Take a look back to see if a workaround has been provided.

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

+3
source

This error was fixed in the latest snet kernel in dotnet, in my case it is the latest version 1.0.0-rc4-004578.
Unfortunately, in the new releases, they decided that the .csproj file did not even need the default compilation templates and resources that would be included by default in msbuild tasks.
Thus, if they are included in your .csproj file, you will not be able to compile it with rc4.

So, here are the steps / changes that did the job for me:

  • download and install dotnet sdk rc4 or higher from https://github.com/dotnet/cli]
  • add the global.json solution / project folder targeting the new dotnet kernel, in my case: { "sdk": { "version": "1.0.0-rc4-004578" } }
  • open the .csproj file and edit it (now you can right in VS 2017); add a debug configuration condition to the elements of the default elements

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

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

    dotnet --versoin

  • publish the release configuration file

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

Please note that we saved the default compilation template section in the .csproj file, but with the debug configuration condition that you need if you want your projects to compile and run in VS 2017 RC, which uses dotnet sdk preview4.
Just keep in mind that your active configuration there needs to be debugged.

You can find more information about the issue discussed here in the dotnet command stream at [ https://github.com/dotnet/cli/issues/4759#issuecomment-274904448]

0
source

Source: https://habr.com/ru/post/1012476/


All Articles