Skip to content
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

fix pack targets to add tfm metadata to output lib files #1255

Merged
merged 1 commit into from
Mar 23, 2017

Conversation

rohit21agrawal
Copy link
Contributor

@rohit21agrawal rohit21agrawal commented Mar 21, 2017

Fixes: NuGet/Home#4840
Fixes: NuGet/Home#4698
Fixes: NuGet/Home#4704

  1. This is long overdue work of adding TargetFramework metadata to build items that need to go into the lib folder in the nupkg. By adding this metadata, we know precisely where in the lib folder an item will go instead of having to search for framework in the path of the file on disk.

  2. This change also adds outputs from SatelliteDLLsProjectOutputGroupOutput and does the appropriate plumbing so they go under their respective culture folders.

  3. An extension point has been provided for executing custom target in the inner build for files that go in the lib (or folder specified via BuildOutputTargetFolder) . A user can write their own custom target and specify it as the value of the property $(TargetsForTfmSpecificBuildOutput). The target should write out any files that need to go into the lib folder into the ItemGroup BuildOutputInPackage and set the following two metadata values :
    a) FinalOutputPath : This is the absolute path of the file on disk (if not provided, the Identity is used to evaluate source path)
    b) TargetPath : This is optional and defaults to the name of the file. Users need to set it when the file needs to go into a subfolder within lib\<TFM> like satellite assemblies which go under their respective culture folders.

  4. An extension point has been provided for files that need to go in the nupkg outside of lib folder but are still TFM specific. A user can write their own custom target and specify it as the value of the property $(TargetsForTfmSpecificContentInPackage). The target should write out any files that need to be included in the nupkg into the ItemGroup TfmSpecificPackageFile and set the following metadata:
    a) PackagePath : Path where the file should be output in the package. NuGet will throw a warning if more than one file is added to the same package path.
    b) BuildAction: Default value has been set to None. This is only required if the package path is in contentFiles folder.

CC: @emgarten @alpaix @jainaashish @nkolev92 @rrelyea @mishra14 @zhili1208

CC: @AArnott to take a look if i covered most of his feedback in NuGet/Home#4698

CC: @onovotny for point 3 and point 4. Would appreciate any feedback on the design.

targetPath = Path.GetFileName(finalOutputPath);
}

if (string.IsNullOrEmpty(targetFramework) || NuGetFramework.Parse(targetFramework) == null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think parse always returns a framework, you may want to check NuGetFramework.Parse(targetFramework).IsSpecificFramework == false which would mean it came back as unsupported or something else that a project should not have.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emgarten fixed.

[Theory]
[InlineData(true)]
[InlineData(false)]
public void PackCommand_PackConsoleAppWithRID_NupkgValid(bool includeSymbols)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there tests for satellite assemblies?

Returns="@(_TargetPathsToAssembliesWithTfm)">
<ItemGroup>
<_TargetPathsToAssembliesWithTfm Include="@(SatelliteDllsProjectOutputGroupOutput)">
<TargetFramework>$(TargetFramework)</TargetFramework>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these have a type property? Any chance they could get mixed up later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emgarten as discussed offline, there is no need for type , as the TargetPath metadata automatically adds culture to the filename.


if (!File.Exists(finalOutputPath))
{
throw new FileNotFoundException(string.Format(Strings.Error_FileNotFound, finalOutputPath));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: set culture to current culture with string.Format, not needed with one param, but generally good to do for user facing errors.

@rohit21agrawal rohit21agrawal force-pushed the dev-ragrawal-packoutputfix branch 2 times, most recently from 810cfdb to ad296ee Compare March 22, 2017 00:17
Copy link
Member

@emgarten emgarten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@rohit21agrawal rohit21agrawal force-pushed the dev-ragrawal-packoutputfix branch 5 times, most recently from bb44dc0 to b8123cc Compare March 22, 2017 22:17
@rohit21agrawal rohit21agrawal force-pushed the dev-ragrawal-packoutputfix branch from b8123cc to 98c6ba1 Compare March 22, 2017 23:42
@clairernovotny
Copy link

How would 4 look in practice?

I imagine that for things like .pp transforms where I'd want them to be included, I could use the existing <None Include="Foo.xml.cs.pp" /> and extend it with Metadata -- BuildAction and PackagePath and it'd "just work."

Not sure why I'd need another set of targets? Having them as None in the solution explorer lets them show up in my solution easily.

@rohit21agrawal
Copy link
Contributor Author

rohit21agrawal commented Mar 23, 2017

@onovotny yes, for anything that is not TFM specific, that would work. But once you have any content (or even build output) that is TFM specific and not covered by the default pack targets, 3 and 4 give you the flexibility to put it at the desirable location within the nuget package.

While (4) is generic enough to cover the functionality of (3), (3) provides stricter control about files that need to go into the lib folder, like setting the right TFM folder names.

Copy link
Member

@emgarten emgarten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@kzu
Copy link
Contributor

kzu commented Apr 11, 2017

  1. again diverges significantly from the simple approach taken by NuGetizer: https://github.com/NuGet/NuGet.Build.Packaging/blob/dev/src/Build/NuGet.Build.Packaging.Tests/AssignPackagePathTests.cs#L273-L275

In Nugetizer, you simply annotate items with the kind (i.e. Lib, Build, Tools) and the right thing happens. Lib, puts the item in the TFM-specific folder according to the project's TF.

If you know where you want to put it instead, you just add either TFM or a TF to the item. That's it. No additional targets, no additional properties.

@rohit21agrawal
Copy link
Contributor Author

rohit21agrawal commented Apr 11, 2017

@kzu 4) is just an extension point for power users and not the default way to pack things, which we implemented because users expressed the need for it. Content is usually not TFM-specific, and that is why default targets include content only in the outer build , however, 4) provides a way for the unusual scenario of including tfm-specific content.

how do you determine which items to check for the pack-specific metadata?

@mhutch
Copy link

mhutch commented Apr 12, 2017

@rohit21agrawal it's documented in the detail in the NuGetizer spec: https://github.com/NuGet/Home/wiki/NuGetizer-Core-Features

@AArnott
Copy link
Contributor

AArnott commented May 5, 2017

Which milestone of VS will this ship with, please?

@rohit21agrawal
Copy link
Contributor Author

15.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants