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

Import from SDKs #1400

Closed
rainersigwald opened this issue Nov 28, 2016 · 10 comments
Closed

Import from SDKs #1400

rainersigwald opened this issue Nov 28, 2016 · 10 comments

Comments

@rainersigwald
Copy link
Member

This is related to #1392, but not a prerequisite for it.

It's currently difficult to determine what the path of an <Import> should be, because it requires knowing how to locate the file to be imported, using properties and relative paths.

#1392 introduces the concept of an "SDK" in order to automatically import an Sdk.props before the user project and an Sdk.targets after it. But that's often not sufficiently granular: sometimes you need to override a target (so your definition must be ordered after the imported one), or set a property before importing an initial target.

Design

<Project>
  <user prop here>
  <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk/1.0.0.0" />
...
  <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk/1.0.0.0" />
  <user target here>
</Project>

Should be syntactic sugar for something like

<Project>
  <user prop here>
  <Import Project="$(MSBuildSDKsPath)\%(___MSBuildSDK.Name)\%(___MSBuildSDK.Version)\Sdk.props" />
...
  <Import Project="$(MSBuildSDKsPath)\%(___MSBuildSDK.Name)\%(___MSBuildSDK.Version)\Sdk.targets" />
  <user target here>
</Project>

This is a) easier to type than the existing mechanism requiring a rooted path and b) doesn't lose any generality, as #1392 does.

@Sarabeth-Jaffe-Microsoft Sarabeth-Jaffe-Microsoft added this to the Visual Studio 15 RTM milestone Nov 29, 2016
@AndyGerlicher AndyGerlicher modified the milestones: MSBuild 15.1 RC.3, Visual Studio 15 RTM Dec 2, 2016
@rainersigwald rainersigwald modified the milestones: MSBuild 15.1 RC.3, MSBuild Sdks Dec 4, 2016
@rainersigwald
Copy link
Member Author

Similar for UsingTask?

@gulbanana
Copy link

gulbanana commented Dec 20, 2016

As a workaround, I'm currently using
<Import Project="$(MSBuildSDKsPath)\Microsoft.NET.SDK\Sdk\Sdk.targets" />
before my custom targets. This works, but emits a warning which sits in the visual studio error list forever :-(

Without it not even AfterBuild was working, presumably because the implicit target import just redefined it.

@jeffkl
Copy link
Contributor

jeffkl commented Dec 20, 2016

@gulbanana this is addressed in the newer implementation which is in PR now: #1492

@gulbanana
Copy link

Great, I'll try it again in a later build.

@codito
Copy link

codito commented Jan 17, 2017

Any idea if #1492 is available on dotnet-cli dev builds?

@rainersigwald
Copy link
Member Author

@codito Yes, it should be. Note that sometimes the "latest" link on the CLI homepage isn't actually the very latest.

@codito
Copy link

codito commented Jan 17, 2017

I can confirm the fix is available on dotnet-cli 1.0.0-rc4-004527. Thanks!

@rainersigwald
Copy link
Member Author

Closing since this is implemented.

On further reflection, I don't think this is needed for UsingTasks. You can always have a .props file next to the task DLL that uses $(MSBuildThisFileDirectory) in its UsingTask.

@kzu
Copy link
Contributor

kzu commented Mar 27, 2017

It works great on VS2017 RTW without specifying an SDK version, like so:

<Project>
	<Import Project="SampleVsix.props" />
	<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
	<PropertyGroup>
		<TargetFrameworks Condition="'$(TargetFrameworks)' == ''">net462;net461</TargetFrameworks>
	</PropertyGroup>
	<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
	<Import Project="SampleVsix.targets" />
</Project>

@AArnott
Copy link
Contributor

AArnott commented Mar 30, 2017

This works for me as well. And in fact I have exactly the same scenario: A VSIX project that must import the language targets before the VSSDK targets.

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

No branches or pull requests

9 participants