novotnyllc / MSBuildSdkExtras

Extra properties for MSBuild SDK projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot use custom AssemblyName per target

vyacheslav-volkov opened this issue · comments

Hi there!

I'm trying to define custom AssemblyName per target but getting nuget error:

Error occurred while restoring NuGet packages: Invalid restore input. Missing required property 'Name'.

here's test project definition:

<Project Sdk="MSBuild.Sdk.Extras">
  <PropertyGroup>
    <TargetFrameworks>monoandroid10.0;xamarin.ios10</TargetFrameworks>
  </PropertyGroup>

  <PropertyGroup>
    <RootNamespace>Test</RootNamespace>
  </PropertyGroup>

  <PropertyGroup Condition=" $(TargetFramework.StartsWith('xamarin.ios')) ">
    <AssemblyName>Test.Ios</AssemblyName>
  </PropertyGroup>

  <PropertyGroup Condition=" $(TargetFramework.StartsWith('monoandroid')) ">
    <AssemblyName>Test.Android</AssemblyName>
  </PropertyGroup>
</Project>

I think you can overcome the issue by setting a <PackageId> property. Then the different <AssemblyName> won't cause issues with NuGet restore.

thanks for the help!
Is this work for you, because for me it generates this error and cannot generate project.assets.json:

C:\Program Files\dotnet\sdk\3.1.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1004: Assets file 'C:\source\repos\TestMultiTarget\TestMultiTarget\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.

For me it worked. I don't know your exact conditions. In my case the project was a Unit Test project that was not referenced by any others and does not generate nugets.
Did you try clean/rebuild/etc?
If you want help share your project file.

I tried everything clean/rebuild/remove obj and bin, maybe it somehow depends on environment. Thanks in advance, here's my test project:

<Project Sdk="MSBuild.Sdk.Extras">
  <PropertyGroup>
    <TargetFrameworks>monoandroid10.0;xamarin.ios10</TargetFrameworks>
  </PropertyGroup>

  <PropertyGroup>
    <RootNamespace>Test</RootNamespace>
  </PropertyGroup>

  <PropertyGroup Condition=" $(TargetFramework.StartsWith('xamarin.ios')) ">
    <AssemblyName>Test.Ios</AssemblyName>
    <PackageId>Test.Ios</PackageId>
  </PropertyGroup>

  <PropertyGroup Condition=" $(TargetFramework.StartsWith('monoandroid')) ">
    <AssemblyName>Test.Android</AssemblyName>
    <PackageId>Test.Android</PackageId>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
  </ItemGroup>
</Project>
namespace Test
{
    public class Class1
    {
        public object Method() => Newtonsoft.Json.Linq.JToken.Parse("");
    }
}

My suggestion was to set to something common, not per configuration. In your case you still get different PackageIds. Try setting it in the first as <PackageId>Test</PackageId>

it works!! thank you for help!