Bug 11220 - SolutionName and SolutionDir are not defined when solution is loaded (and during Package/Deployment time as well)
Summary: SolutionName and SolutionDir are not defined when solution is loaded (and dur...
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Android ()
Version: 3.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2013-03-18 01:54 UTC by Virgile Bello
Modified: 2016-04-19 10:14 UTC (History)
8 users (show)

Is this bug a regression?: ---
Last known good build:

Test project to reproduce the issue. (12.24 KB, application/octet-stream)
2013-08-23 01:12 UTC, Virgile Bello

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Virgile Bello 2013-03-18 01:54:37 UTC
Let's say I have something using $(SolutionName) or $(SolutionDir) in my csproj.

From Visual Studio UI, Build will work fine.
However, during deployment on Android device (package creation) the variables will be undefined.
Comment 1 Miguel de Icaza [MSFT] 2013-05-22 16:12:43 UTC

Can you show me a log, or screenshot of where the problem happens?
Comment 2 Virgile Bello 2013-07-08 07:14:39 UTC
Let's say I have something like that in my .csproj:

<Import Project="$(SolutionDir)\Test.targets" />

This .csproj will load fine if it's a normal .NET dll, but if it's a Mono Android project, it will complain that C:\Test.targets doesn't exist at project load time (because SolutionDir is not properly set). The project will simply not load and appear as unavailable.

As a workaround I currently set SolutionName and SolutionDir before opening visual studio, but that's really not user-friendly for deployment.

Also as far as I can remember I think that there was some other problems during Install build target (even when Build one was OK), but not sure about that (need first issue to be fixed to make sure).
Comment 3 Virgile Bello 2013-08-23 01:12:46 UTC
Created attachment 4698 [details]
Test project to reproduce the issue.

Test project for this issue.

.csproj contains <Import Project="$(SolutionDir)\Test.targets" />
This works fine for Windows solution, but in Monodroid (ProjectTypeGuids defined), I get this error:
error  : The imported project "C:\Test.targets" was not found

This is because SolutionDir and SolutionName are undefined when parsing the csproj.

I think it also happens with iOS.
Comment 4 Virgile Bello 2013-08-23 01:13:36 UTC
Reopened (added attachment to reproduce the issue easily).
Comment 5 Nathan B. Evans 2013-09-05 12:24:09 UTC
I had a similar issue where the .csproj (Android project) would load fine into VS and it would even Build/Rebuild fine. But when I went to Start Debugging on the project (which involves packaging it) it would fail during the packaging step.

I traced this down to being related to my VersionAssemblyInfo.targets (a small known-good util I use to set the version info of the assembly to my latest git commit hash amongst other things). This targets file was using the $(SolutionDir) property in its script. But for some reason this property was set to a relative path of "..\..\..\..\". Which is technically valid, provided I had prefixed it with the $(ProjectDir) property as well. But doing this would have broken my other projects in the solution which weren't exhibiting this odd behaviour.

In the end I went in search for an equivalent property that had the same effect as SolutionDir but which wasn't broken in this way. I found one called $(MSBuildThisFileDirectory). This worked for me because the VersionAssemblyInfo.targets file was in the root solution folder.
Comment 6 pierre 2013-11-14 21:53:47 UTC

I have the same problem here.
It would be great if it could be fixed.
Comment 7 Virgile Bello 2014-04-04 01:43:52 UTC
Any progress?

We really hope this could be fixed before we release our product (otherwise it involves ugly workaround i.e. opening solution through a .bat file to have SolutionName/SolutionDir defined as env. variable).
Comment 8 Virgile Bello 2014-04-04 02:52:10 UTC
Note: Probably the only thing you have to do is add SolutionName and SolutionDir to the BuildRequestData you send to the BuildManager.
Comment 9 Joaquin Jares 2015-11-03 14:16:28 UTC
We changed the way Android deploys to be pure MSBuild based, and that should fix this bug. This is now in alpha. Marking this bug as fixed for verification, please reopen if this is still an issue.
Comment 10 Pang 2016-04-19 10:14:07 UTC

I'm using the latest Xamarin.Android for VS2013.
This issue is still there.

This time, "$(SolutionDir)" will actually show "$(ProjectDir)*Undefined*"