Skip to content

Commit

Permalink
Merge pull request #131 from Microsoft/develop
Browse files Browse the repository at this point in the history
Create release
  • Loading branch information
heaths committed Jan 23, 2018
2 parents f1a9c6c + 0cacce7 commit f154130
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 23 deletions.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Visual Studio Locator
=====================

[![build status: master](https://ci.appveyor.com/api/projects/status/yy3g7rggm2sx4nam/branch/master?svg=true)](https://ci.appveyor.com/project/heaths/vswhere/branch/master)
![build status: master](https://devdiv.visualstudio.com/_apis/public/build/definitions/0bdbc590-a062-4c3f-b0f6-9383f67865ee/5581/badge)
[![github release](https://img.shields.io/github/release/Microsoft/vswhere.svg?logo=github)](https://github.com/Microsoft/vswhere/releases/latest)
[![github releases: all](https://img.shields.io/github/downloads/Microsoft/vswhere/total.svg?logo=github&label=github)](https://github.com/Microsoft/vswhere/releases)
[![chocolatey: all](https://img.shields.io/chocolatey/dt/vswhere.svg)](https://chocolatey.org/packages/vswhere)
[![nuget: all](https://img.shields.io/nuget/dt/vswhere.svg?label=nuget)](https://nuget.org/packages/vswhere)

Over the years Visual Studio could be discovered using registry keys, but with recent changes to the deployment and extensibility models a new method is needed to discover possibly more than once installed instance. These changes facilitate a smaller, faster default install complimented by on-demand install of other workloads and components.

_vswhere_ is designed to be a redistributable, single-file executable that can be used in build or deployment scripts to find where Visual Studio - or other products in the Visual Studio family - is located. For example, if you know the relative path to MSBuild, you can find the root of the Visual Studio install and combine the paths to find what you need.
Expand Down Expand Up @@ -33,13 +40,4 @@ To file issues or suggestions, please use the [Issues](https://github.com/Micros

## License

This project is licensed under the [MIT license](LICENSE.txt).

## Status

This project uses a Git flow model releasing from the `master` branch with development based on and stabilized in the `develop` branch.

Branch | AppVeyor | VSTS
------ | ------ | -------
master | [![build status: master](https://ci.appveyor.com/api/projects/status/yy3g7rggm2sx4nam/branch/master?svg=true)](https://ci.appveyor.com/project/heaths/vswhere/branch/master) | ![build status: master](https://devdiv.visualstudio.com/_apis/public/build/definitions/0bdbc590-a062-4c3f-b0f6-9383f67865ee/5581/badge)
develop | [![build status: develop](https://ci.appveyor.com/api/projects/status/yy3g7rggm2sx4nam/branch/develop?svg=true)](https://ci.appveyor.com/project/heaths/vswhere/branch/develop)
This project is licensed under the [MIT license](LICENSE.txt).
13 changes: 13 additions & 0 deletions docker/Tests/vswhere.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,21 @@ Describe 'vswhere' {
@($instances.instances.instance).Count | Should Be 1
@($instances.instances.instance)[0].instanceId | Should Be 2
}

It 'returns 0 instances with multiple requirements' {
$instances = C:\bin\vswhere.exe -requires microsoft.visualstudio.workload.azure microsoft.visualstudio.workload.nativedesktop -format json | ConvertFrom-Json
$instances.Count | Should Be 0
}
}

Context '-requiresAny' {
It 'returns 1 instance with multiple requirements' {
$instances = C:\bin\vswhere.exe -requires microsoft.visualstudio.workload.azure microsoft.visualstudio.workload.nativedesktop -requiresAny -format json | ConvertFrom-Json
$instances.Count | Should Be 1
$instances[0].instanceId | Should Be 2
}
}

Context '-version' {
It 'returns 1 instance using "text"' {
$instanceIds = C:\bin\vswhere.exe -version '(15.0.26116,]' | Select-String 'instanceId: \w+'
Expand Down
4 changes: 4 additions & 0 deletions src/vswhere.lib/CommandArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ void CommandArgs::Parse(_In_ vector<CommandParser::Token> args)
{
ParseArgumentArray(it, args.end(), arg, m_requires);
}
else if (ArgumentEquals(arg.Value, L"requiresAny"))
{
m_requiresAny = true;
}
else if (ArgumentEquals(arg.Value, L"version"))
{
m_version = ParseArgument(it, args.end(), arg);
Expand Down
6 changes: 6 additions & 0 deletions src/vswhere.lib/CommandArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class CommandArgs
return m_requires;
}

const bool get_RequiresAny() const noexcept
{
return m_requiresAny;
}

const std::wstring& get_Version() const noexcept
{
return m_version;
Expand Down Expand Up @@ -124,6 +129,7 @@ class CommandArgs
bool m_productsAll;
std::vector<std::wstring> m_products;
std::vector<std::wstring> m_requires;
bool m_requiresAny;
std::wstring m_version;
bool m_latest;
bool m_legacy;
Expand Down
16 changes: 8 additions & 8 deletions src/vswhere.lib/Formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,46 +94,46 @@ wstring Formatter::FormatDateISO8601(_In_ const FILETIME& value)

wstring Formatter::FormatDate(_In_ const FILETIME& value)
{
FILETIME local = {};
SYSTEMTIME st = {};
SYSTEMTIME stUniversal = {};
SYSTEMTIME stLocal = {};
wstring date;
wstring time;

if (!::FileTimeToLocalFileTime(&value, &local))
if (!::FileTimeToSystemTime(&value, &stUniversal))
{
throw win32_error();
}

if (!::FileTimeToSystemTime(&local, &st))
if (!::SystemTimeToTzSpecificLocalTime(NULL, &stUniversal, &stLocal))
{
throw win32_error();
}

// Format date
auto cch = ::GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, NULL, 0);
auto cch = ::GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stLocal, NULL, NULL, 0);
if (!cch)
{
throw win32_error();
}

date.reserve(cch);
date.resize(cch - 1);
cch = ::GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, const_cast<LPWSTR>(date.c_str()), cch);
cch = ::GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stLocal, NULL, const_cast<LPWSTR>(date.c_str()), cch);
if (!cch)
{
throw win32_error();
}

// Format time
cch = ::GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, NULL, 0);
cch = ::GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &stLocal, NULL, NULL, 0);
if (!cch)
{
throw win32_error();
}

time.reserve(cch);
time.resize(cch - 1);
cch = ::GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, const_cast<LPWSTR>(time.c_str()), cch);
cch = ::GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &stLocal, NULL, const_cast<LPWSTR>(time.c_str()), cch);
if (!cch)
{
throw win32_error();
Expand Down
8 changes: 8 additions & 0 deletions src/vswhere.lib/InstanceSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@ bool InstanceSelector::IsWorkloadMatch(_In_ ISetupInstance2* pInstance) const
}
}

if (m_args.get_RequiresAny())
{
return any_of(found.begin(), found.end(), [](MapType::const_reference pair) -> bool
{
return pair.second;
});
}

return all_of(found.begin(), found.end(), [](MapType::const_reference pair) -> bool
{
return pair.second;
Expand Down
Binary file modified src/vswhere.lib/vswhere.lib.rc
Binary file not shown.
39 changes: 39 additions & 0 deletions test/vswhere.test/InstanceSelectorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,45 @@ TEST_CLASS(InstanceSelectorTests)
Assert::AreEqual<size_t>(1, selected.size());
}

BEGIN_TEST_METHOD_ATTRIBUTE(Select_RequiresAny_Workload)
TEST_WORKITEM(126)
END_TEST_METHOD_ATTRIBUTE()
TEST_METHOD(Select_RequiresAny_Workload)
{
TestPackageReference product =
{
{ L"Id", L"Microsoft.VisualStudio.Product.Enterprise" },
};

TestPackageReference managedDesktop = { { L"Id", L"Microsoft.VisualStudio.Workload.ManagedDesktop" } };
TestPackageReference nativeDesktop = { { L"Id", L"Microsoft.VisualStudio.Workload.NativeDesktop" } };
vector<TestInstance::ElementType> packages =
{
&managedDesktop,
&nativeDesktop,
};

TestInstance::MapType properties =
{
{ L"InstanceId", L"a1b2c3" },
{ L"InstallationName", L"test" },
};

TestInstance instance(&product, packages, properties);
TestEnumInstances instances =
{
&instance,
};

CommandArgs args;
args.Parse(L"vswhere.exe -requires microsoft.visualstudio.workload.azure microsoft.visualstudio.workload.nativedesktop -requiresAny");

InstanceSelector sut(args);
auto selected = sut.Select(&instances);

Assert::AreEqual<size_t>(1, selected.size());
}

TEST_METHOD(Select_Invalid_Version_Range)
{
CommandArgs args;
Expand Down
4 changes: 2 additions & 2 deletions test/vswhere.test/TextFormatterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ TEST_CLASS(TextFormatterTests)

auto expected =
L"instanceId: a1b2c3\n"
L"installDate: 2/22/2017 6:22:35 PM\n"
L"installDate: 2/22/2017 5:22:35 PM\n"
L"installationName: test\n"
L"properties_campaignId: abcd1234\n"
L"properties_nickname: test\n";
Expand Down Expand Up @@ -392,7 +392,7 @@ TEST_CLASS(TextFormatterTests)

auto expected =
L"instanceId: a1b2c3\n"
L"installDate: 2/22/2017 6:22:35 PM\n"
L"installDate: 2/22/2017 5:22:35 PM\n"
L"installationName: test\n"
L"isPrerelease: 0\n"
L"catalog_productLineVersion: 2017\n"
Expand Down
4 changes: 2 additions & 2 deletions test/vswhere.test/ValueFormatterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ TEST_CLASS(ValueFormatterTests)

auto expected =
L"a1b2c3\n"
L"2/22/2017 6:22:35 PM\n"
L"2/22/2017 5:22:35 PM\n"
L"test\n"
L"abcd1234\n"
L"test\n";
Expand Down Expand Up @@ -365,7 +365,7 @@ TEST_CLASS(ValueFormatterTests)

auto expected =
L"a1b2c3\n"
L"2/22/2017 6:22:35 PM\n"
L"2/22/2017 5:22:35 PM\n"
L"test\n"
L"0\n"
L"2017\n"
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "2.2",
"version": "2.3",
"publicReleaseRefSpec": [
"^refs/heads/master$",
"^refs/heads/release/",
Expand Down

0 comments on commit f154130

Please sign in to comment.