{"action":"opened","issue":{"url":"https://api.github.com/repos/xunit/xunit/issues/281","labels_url":"https://api.github.com/repos/xunit/xunit/issues/281/labels{/name}","comments_url":"https://api.github.com/repos/xunit/xunit/issues/281/comments","events_url":"https://api.github.com/repos/xunit/xunit/issues/281/events","html_url":"https://github.com/xunit/xunit/issues/281","id":56067141,"number":281,"title":"Add msbuild targets file to xUnit NuGet package","user":{"login":"robv8r","id":251736,"avatar_url":"https://avatars.githubusercontent.com/u/251736?v=3","gravatar_id":"","url":"https://api.github.com/users/robv8r","html_url":"https://github.com/robv8r","followers_url":"https://api.github.com/users/robv8r/followers","following_url":"https://api.github.com/users/robv8r/following{/other_user}","gists_url":"https://api.github.com/users/robv8r/gists{/gist_id}","starred_url":"https://api.github.com/users/robv8r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robv8r/subscriptions","organizations_url":"https://api.github.com/users/robv8r/orgs","repos_url":"https://api.github.com/users/robv8r/repos","events_url":"https://api.github.com/users/robv8r/events{/privacy}","received_events_url":"https://api.github.com/users/robv8r/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-30T18:25:57Z","updated_at":"2015-01-30T18:25:57Z","closed_at":null,"body":"Problem\r\n----------\r\nAccording to the wiki page titled [How To Use MSBuild](https://xunit.codeplex.com/wikipage?title=HowToUseMSBuild), one can use markup similar to the following to get xUnit MsBuild support.  \r\n```xml\r\n<Project\r\n    DefaultTargets=\"Test\"\r\n    xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n\r\n  <UsingTask\r\n    AssemblyFile=\"xunit.runner.msbuild.dll\"\r\n    TaskName=\"Xunit.Runner.MSBuild.xunit\"/>\r\n\r\n  <Target Name=\"Test\">\r\n    <xunit Assembly=\"MyTests\\bin\\Debug\\MyTests.dll\" />\r\n  </Target>\r\n\r\n</Project>\r\n```\r\nThis approach works well.  However, it's not as clean when referencing the xUnit NuGet package in a .csproj file.  To do this, one would need markup similar to the following:\r\n\r\n```xml\r\n<Project\r\n    DefaultTargets=\"Build\"\r\n    xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n\r\n  <!-- .csproj file contents ommitted -->\r\n\r\n  <UsingTask\r\n    AssemblyFile=\"..\\packages\\xunit.1.9.2\\lib\\net20\\xunit.runner.msbuild.dll\"\r\n    TaskName=\"Xunit.Runner.MSBuild.xunit\"/>\r\n\r\n  <Target Name=\"AfterBuild\">\r\n    <xunit Assembly=\"MyTests\\bin\\Debug\\MyTests.dll\" />\r\n  </Target>\r\n\r\n</Project>\r\n```\r\nIn the example above, the path to the xunit.runner.msbuild.dll file found in the NuGet package is hard coded in the .csproj file.  While this works, it's not ideal.  The approach is tied to a specific version of the NuGet package.  When version 1.9.3 or 2.0.0 of xUnit comes out, the developer will need to edit the .csproj file to point to the new package. \r\n\r\nProposal\r\n----------\r\nNuGet provides a means to include .props and .targets files that are inserted into a .csproj file when the NuGet package is applied.  One option would be to include a .targets file that declared the `UsingTask` similar to how the new xUnit Visual Studio runner imports its test adapter.\r\n\r\nThe structure of the existing xUnit NuGet Package (1.9.2) looks like this:\r\n```\r\n+---xunit.1.9.2\r\n    \\---lib\r\n        \\---net20\r\n            |---xunit.dll\r\n            |---xunit.dll.tdnet\r\n            |---xunit.runner.msbuild.dll\r\n            |---xunit.runner.tdnet.dll\r\n            |---xunit.runner.utility.dll\r\n            \\---xunit.xml\r\n```\r\n\r\nThe proposed structure would look like this:\r\n```\r\n+---xunit.1.9.2\r\n    |---lib\r\n    |   \\---net20\r\n    |       |---xunit.dll\r\n    |       |---xunit.dll.tdnet\r\n    |       |---xunit.runner.msbuild.dll\r\n    |       |---xunit.runner.tdnet.dll\r\n    |       |---xunit.runner.utility.dll\r\n    |       \\---xunit.xml\r\n    \\---build\r\n        \\---xunit.targets\r\n```\r\n\r\nThe new .targets file could be similar to the following:\r\n### xunit.targets\r\n```xml\r\n<Project\r\n    xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n\r\n  <UsingTask\r\n    AssemblyFile=\"$(MSBuildThisFileDirectory)..\\lib\\net20\\xunit.runner.msbuild.dll\"\r\n    Condition=\"Exists('$(MSBuildThisFileDirectory)..\\lib\\net20\\xunit.runner.msbuild.dll')\"\r\n    TaskName=\"Xunit.Runner.MSBuild.xunit\"/>\r\n  \r\n</Project>\r\n```\r\n\r\nThis would reduce the amount of changes to the .csproj file a developer would need to do to run tests on build. The first example could now be reduced to the following:\r\n\r\n```xml\r\n<Project\r\n    DefaultTargets=\"Build\"\r\n    xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n\r\n  <!-- .csproj file contents ommitted -->\r\n\r\n  <Target Name=\"AfterBuild\">\r\n    <xunit Assembly=\"$(TargetPath)\" />\r\n  </Target>\r\n\r\n</Project>\r\n```"}}