How does one get the full physical path of the .sln file when scripting in MSBuild?
I'm trying to force nuget to download packages using:
<Target Name="BeforeCompileConfiguration">
<Exec Command=""$(ToolsHome)NuGet\NuGet.exe" restore "$(SolutionRoot)\KK\MyProject.sln"" />
</Target>
KK is the name of the folder that the .sln file is under. I'd like to replace
$(SolutionRoot)\KK\MyProject.sln
with a single $() build property.
$(SolutionPath)
should do your job!
By the way it's equivalent to:
$(SolutionDir)$(SolutionFileName)
Related
I have two license files that I would like to include in my \bin directory both when I build and publish.
Both files are in the App_Data directory (their initial location doesn't matter, they just need to end up in the \bin) and have the following properties set:
Build Action = Content
Copy to Output Directory = Copy Always
They are in not the \bin when I build or publish.
What is wrong with my setup: the settings, the folders, the files, something else...?
UPDATE
I moved the files out of the App_Data directory and placed them in the project root and now they are copied to the \bin on build.
I've done this in a few projects by expanding my .csproject file slightly. The following code should be put directly beneath the Project node in your WebProject.csproj.
The AfterBuild target simply copies a set of files ("unreferenced DLLs" in this case) to the bin-folder when building normally from Visual Studio. The CustomCollectFiles basically do the same thing when deploying.
<PropertyGroup>
<UnreferencedDlls>..\lib\Unreferenced\**\*.dll</UnreferencedDlls>
</PropertyGroup>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="AfterBuild">
<Message Text="Copying unreferenced DLLs to bin" Importance="High" />
<CreateItem Include="$(UnreferencedDlls)">
<Output TaskParameter="Include" ItemName="_UnReferencedDLLs" />
</CreateItem>
<Copy SourceFiles="#(_UnReferencedDLLs)" DestinationFolder="bin\%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>
<Target Name="CustomCollectFiles">
<Message Text="Publishing unreferenced DLLs" Importance="High" />
<ItemGroup>
<_CustomFiles Include="$(UnreferencedDlls)" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
The part you need to modify is basically the UnreferencedDlls node to match your folder structure. The **\*.dll part simply means "every DLL file at any level beneath here".
If you're using Visual Studio:
Show your file properties (Click on your file or Right-click on it then choose Properties)
At the Copy to Output Directory property choose Copy always or Copy if newer.
At build time, the file is going to be copied at the bin directory: Debug or Release...
not necessarily a direct answer, but I highly suggest not using the baked in "publish" mechanism, but rather wire up a build script (probably in powershell) that will do everything you need. It's really easy to hook into MSBuild as well as nUnit and also copy files and move them around.
POWERSHELL (rough) example.
# Get Directory Location
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
# Build the application using MSBuild
cmd /c C:\Windows\Microsoft.NET\Framework\$v4_net_version\msbuild.exe "$directorypath\MyProject.sln" /p:Configuration=Release
# Run the tests using nUnit
cmd /c $directorypath\build\nunit\nunit-console.exe $solutionPath\MyProject.Tests\bin\debug\MyProject.Tests.dll
# Copy the license to the appropriate directory
Copy-Item -LiteralPath "$directorypath\mylicensefile.txt" "$directorypath\bin\release" -Force
# NOTE: You are going to have to adjust this to match your solution and projects.
In this post on Microsoft Connect the answer is much simpler:
Referenced assemblies in Unit Test are not copied in TestResults/Out
So what I did was the following:
[TestClass]
[DeploymentItem("Some.dll")]
public class SomeTests
{
...
}
It works fine for me.
Hope it help.
I am trying to create a rpm package using ant task for that I need to create specfile which will have all the file names in the following format
%attr(0755, root, root) %dir dir1
%attr(0755, root, root) %dir dir1/dir2
%attr(0755, root, root) %dir dir1/dir2/dir3
%attr(0500, root, root) dir1/file1
%attr(0500, root, root) dir1/dir2/file1
I have such directory structure created during my build process but using ant I am not able to list all the files and directories which I can then write into my specfile
following is what I have tried to list the files but it does not differentiate between files and directory , moreover I need some way to iterate over the list.
<fileset id="dist.contents" dir="${nativePackageDir}" includes="**"/> |
<property name="prop.dist.contents" refid="dist.contents"/> | <target name="javaobject-library" depends="props">
<echo>${prop.dist.contents}</echo>
<dirset id="dist.contents" dir="${nativePackageDir}" includes="*"/>
<property name="prop.dist.contents" refid="dist.contents"/>
<echo>${prop.dist.contents}</echo>
Using dirset instead of fileset should fix your problem.
You simply have to write in java an ant task implementation, to which you'll provide as parameters the input directory and the path of the specfile you want to be written.
I find it better and more manageable to have reusable ant tasks in java, instead of having gigantic ant xml files.
I want to take latest source from the Team Foundation Source control project directory to my local machine directory using NAnt build script.
for that i have used:-
<?xml version="1.0"?>
<project name="TFUse_GetFiles" default="GetTFSFiles">
<target name="GetTFSFiles" >
<exec program="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe">
<arg value="get" />
<arg value="/login:Domain name\loginid,password" />
<arg value="$/Projects/dir/Main" />
<arg value="/force" />
</exec>
</target>
</project>
the result is showing as [exec]All files are up to date , but no files are copied to my local folder..
So please help me about this probleam if any body has done above mentioned task before.
Thanks,
The TFS client will only download files that are out of date according to the TFS server: it knows previous what gets have taken place to the workspace.
You could use the /force option on tf get to get everything whatever the server has recorded.
It's like Richard says, in addition: if your $/Projects/dir/Main is not a valid source path, TF.exe again replies with "All files are up to date".
You can find the valid path by navigating within source control explorer to the target path & then checking the 'Source location' entry.
Adding /recursive as an argument solved my problem of NAnt returning "All files are up to date" even though there were in fact new and updated files to get.
I start studying ANT today in order to make Java compiling easier.
I wrote simple ANT script which only use javac command.
What I am trying is compile from .....\head_first\src\com\masatosan\constant.java (source)
to the destination directory:
.....\head_first\WEB-INF\classes\com\masatosan\conf
So the result would look like:
.....\head_first\WEB-INF\classes\com\masatosan\conf\constant.class
But I can't figure out why the actual result adds "/com/masatosan/conf" directories to the destination folder, so it looks like:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\WEB-INF\classes\com\masatosan\conf\com\masatosan\constant.class
Could anyone tell me how can I fix this?
ANT
<project name="CompileMasatosan"
basedir="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\src\com\masatosan">
<description>
masatosan compiler
</description>
<property name="confSrc"
location="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\src\com\masatosan\conf" />
<property name="confDest"
location="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\WEB-INF\classes\com\masatosan\conf" />
<target name="compileConfSrc">
<javac srcdir="${confSrc}" destdir="${confDest}" />
</target>
</project>
UPDATE
I didn't know complier creates directories based on the package name.
The package name of constant.java was com.masatosan.conf so that complier creates "/com/masatosan/conf/"
You're trying to tell ANT to change the package because you want Constant.class to be under the com.masatosan.conf package rather than the com.masatosan package. The Ant compilation process will create the appropriate package subdirectories, which is why you see com\masatosan created under the dest.
I don't think you can tell ANT to change the package of a source file, which is what you're trying to do by injecting an extra conf dir. You can either create a conf dir and have a conf\com\masatosan\constants.class or put it under classes\com\masatosan\constants.class, but you can't do com\masatosan\conf\constants.class since that changes the package of constants.class to com.masatosan.conf
Or simply change the package of constants.class to com\masatosan\conf and change your ant file to to:
<property name="confDest"
location="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\WEB-INF\classes" />
Its because of the package name. You have a Java file in package com.masatosan. You can fix this two way either move class to default package or set ${confDest} value to \head_first\WEB-INF\classes\ only.
This is because the compiler is creating the package directory stucture under the destination directory you specify. The constant class is in the com.masatosan package, so under classes\com\masatosan\conf, the compiler creates a further two directories for the package, com\masatosan, and places the compiled class (constant.class) in there.
Your destination directory should simply be C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\WEB-INF\classes. The com and masatosan directories will be created for you.
I'm trying to use Nant to compile an ASP.NET MVC app, so far my build script just runs ms build and runs some other tasks, however I want my compiled files to be put in a "build" directory, how can I tell msbuild where to put the compiled files?
Looking here:
http://msdn.microsoft.com/en-us/library/ms164311.aspx
it specifies that you can set msbuild to override the output dir setting in your project file, like so:
/properties:OutputDir=bin\Debug
Is this what you want?
you can put this in your project file (or in an imported project file if you want reuse), it will override both the path for the executable/dll and the path where the .obj files etc go.
<PropertyGroup>
<OutputPath>c:\bin</OutputPath>
<BaseIntermediateOutputPath>c:\temp\$(AssemblyName)</BaseIntermediateOutputPath>
</PropertyGroup>
If you are using the <msbuild> task from NAntContrib, then you can set the OutputDir property like this:
<msbuild project="path-to-sln-or-csproj-or-msbuild" target="Build">
<properties>
<property name="OutputDir" value="build-outdir-dir" />
</properties>
</msbuild>