Based on documentation in MSDN it can't be done using the old regular way.
Visual web parts don't directly support SharePoint server tokens such as $SPUrl. For more information, see "Token Restrictions in Sandboxed Visual Web Parts".
Visual web parts in sandboxed solutions can't process standard tokens, such as $SPUrl, that the SharePoint runtime supports. As a result, the URL isn't resolved, and you can't preview the content in Design view in the visual web part designer if you refer to it directly in a script element, such as in the following example:
<script src=”<% $SPUrl:~site/SiteAssets/ListOperations.js %>"></script>
To work around this limitation and resolve the token, refer to it by using literals:
<asp:literal ID="Literal1" runat="server" Text="<script src='" />
<asp:literal ID="Literal2" runat="server" Text="<% $SPUrl:~site/SiteAssets/ListOperations.js %>" />
More info on MSDN: Troubleshooting SharePoint Solutions