-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dotnet pack does not respect assembly atttributes #9011
Comments
msbuild-integrated NuGet takes its version from the A workaround which works only using full-framework msbuild ( <Project>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);ReadPackageVersionFromOutputAssembly</GenerateNuspecDependsOn>
</PropertyGroup>
<Target Name="ReadPackageVersionFromOutputAssembly" DependsOnTargets="Build">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="PackAssembly" />
</GetAssemblyIdentity>
<PropertyGroup>
<PackageVersion>%(PackAssembly.Version)</PackageVersion>
</PropertyGroup>
</Target>
</Project> for a multi-targeting project (https://stackoverflow.com/questions/48065516/build-project-with-multiple-targetframeworks-in-tfs-as-nuget-package/48069440#48069440): <Target Name="ReadPackageVersionFromOutputAssemblySingleTfm" Returns="@(PackAssembly)" Condition="'$(IsCrossTargetingBuild)' != 'true'">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="PackAssembly" />
</GetAssemblyIdentity>
<PropertyGroup>
<PackageVersion>%(PackAssembly.Version)</PackageVersion>
</PropertyGroup>
</Target>
<Target Name="ReadPackageVersionFromOutputAssemblyMultipleTfms" Condition="'$(IsCrossTargetingBuild)' == 'true'">
<PropertyGroup>
<FirstTargetFramework>$([System.String]::Copy($(TargetFrameworks)).Split(';').GetValue(0))</FirstTargetFramework>
</PropertyGroup>
<MSBuild Projects="$(MSBuildProjectFullPath)" Targets="ReadPackageVersionFromOutputAssemblySingleTfm" Properties="TargetFramework=$(FirstTargetFramework)">
<Output TaskParameter="TargetOutputs" ItemName="PackAssembly" />
</MSBuild>
<PropertyGroup>
<PackageVersion>%(PackAssembly.Version)</PackageVersion>
</PropertyGroup>
</Target>
<Target Name="ReadPackageVersionFromOutputAssembly" DependsOnTargets="Build;ReadPackageVersionFromOutputAssemblySingleTfm;ReadPackageVersionFromOutputAssemblyMultipleTfms"> |
@rohit21agrawal should I move this issue to nuget? @dasMulli as always, thank you very much for the reply. |
@livarcocc I don't think nuget reading from the aseemblyinfo file is a good idea, given how pack is written, all our inputs should come from msbuild properties. I would hope that SDK would be in a much better position to translate assemblyinfo properties to msbuild properties. |
@rohit21agrawal who does the work is something that can be discussed and figure out later. I am wondering if it even makes sense for pack to pick up the AssemblyVersion for the Package version. And in what circumstance. I am not comfortable designing that interaction and going around pack for it. Independently of where the code lives. |
@livarcocc my point was that even if we do want to design the scenario where a package version should be equal to AssemblyVersion, the AssemblyVersion should be fed to Regardless, I just remembered that an AsssemblyInfo.cs file should not really be required, because setting an AssemblyVersion can be achieved in a csproj file as well. Here is how NuGet does it for it's projects: https://github.com/NuGet/NuGet.Client/blob/dev/build/common.project.props#L168-L209 |
@dasMulli your solution resolves the assembly version. What about title, description, etc?
|
@dasMulli Your solution works for me perfectly while using msbuild. I am attempting to convert projects over to the new format and start using dotnet to build all of them. This one solution is also a nuget package that requires custom versioning, which is passed in through build arguments and then we modify the AssemblyVersion through another task that is currently also not working with dotnet build (another issue). Using dotnet pack, I am getting the following error:
Any ideas? |
@obylium It should work on 2.1.300+ CLI versions as this task was introduced for newer msbuild versions (dotnet/msbuild#2933) |
Actually it may already be in 2.1.200+ but I'm not 100% sure. |
@dasMulli I just tried 2.1.300 and it worked. Thanks. |
I'm using Visual Studio 2017 (15.9.5). My .Net Standard 2.0 project is using an AssemblyInfo.cs file. When building the nuget package this information is ignored (as explained here, fine by me). What's confusing is that after the project was compiled, the "Package" tab of the project settings in Visual Studio does show the information from the AssemblyInfo attributes (if necessary, close and reopen the project settings tab). |
Due to lack of recent activity, this issue has been labeled as 'stale'. It will be closed if no further activity occurs within 30 more days. Any new comment will remove the label. |
This issue will now be closed since it has been labeled 'stale' without activity for 30 days. |
@junalmeida commented on Tue Jan 09 2018
Issue Title
Compiling and packing using Visual Studio 2017 or dotnet pack does not respect assembly attributes while using AssemblyInfo.cs
General
Using the following csproj structure:
When building the project, binaries are generated correctly with my attributes from .cs file, but nuget package is wrong:
The text was updated successfully, but these errors were encountered: